Assign a variable to number of lines in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Assign a variable to number of lines in a file
# 1  
Old 06-19-2013
Assign a variable to number of lines in a file

Hello Gurus,

Here is my requirement. I need to find the number of lines in a file and need to assign it to a variable. This is what I did and not wroking.

Code:
#!/bin/ksh
set -xv
Src_Path=/mac/dev/Generic/SrcFiles
Src_Count=wc -l  ${Src_Path}/FILE_JUNE.txt
Count_file = $Src_Count | awk -F
echo "Record Count of FILE_JUNE.txt is :" $Count_file

exit 0

Thanks,
Sri
# 2  
Old 06-19-2013
Code:
#!/bin/ksh

Src_Path="/mac/dev/Generic/SrcFiles"

line_count=$( wc -l < "${Src_Path}/FILE_JUNE.txt" )

echo "Record Count of FILE_JUNE.txt is : $line_count"

This User Gave Thanks to Yoda For This Post:
# 3  
Old 06-19-2013
Thanks so much Yoda. This was my first post on this forum and it was successful.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Assign variable value from file to another with the same name

Hi All, I need to read two config files in a shell script. In that I need to assign a value from one config file to another. I 'm using bash. config_env.txt prefix=tab_ config_properties.txt table_name=${prefix}account So, when I read these two files in a shell script, I need... (6 Replies)
Discussion started by: shash
6 Replies

2. Shell Programming and Scripting

Assign number of records to a variable

How does one assign a variable, x to equal the number of records in a different file. I have a simple command such as below: awk -F "\t" '(NR>5) { if(($x == "0/0")) { print $0} }' a.txt > a1.txt but I want x to equal the number of records in a different file, b.txt (10 Replies)
Discussion started by: Geneanalyst
10 Replies

3. Shell Programming and Scripting

Assign large number of blanks to a variable

I want to assign large number of blanks to a variable in Korn shell. If it is a small number it is fine like if I want to assign 3 blanks I would code var=" " But if it is a big number say 100 blanks, what is a better way? Ultimately I will use it in printf statement printf... (3 Replies)
Discussion started by: Soham
3 Replies

4. UNIX for Dummies Questions & Answers

Assign line from file to variable

Hi, I am new to shell scripting. Need help with the below requirement. I need help to read a log file and line containing word ORA needs to be captured into a variable and the values of the variable need to be inserted into a table. For E.g. file test.sql has below error: ORA-01017:... (3 Replies)
Discussion started by: ricsharm
3 Replies

5. Shell Programming and Scripting

Insert a variable to a text file after fixed number of lines

Hi, I am new to unix. I need to insert a variable which contains some lines of text into a text file after fixed number of lines.. Please help me on this.. Thanks in Advance, Amrutha (3 Replies)
Discussion started by: amr89
3 Replies

6. Shell Programming and Scripting

How to assign a shell variable to a NUMBER parameter in pl/sql?

I have the below script running for generating file from PL/SQL stored procedure. I need to declare a shell variable and then pass this to sqlplus command to pass the same as a INPUT parameter for the stored procedure. Please help to do this. #!/bin/sh minlimit=0 maxlimit=10 size=100 while... (0 Replies)
Discussion started by: vel4ever
0 Replies

7. Shell Programming and Scripting

Get letter from number and assign to a variable

Hi to all in forum, I'm trying to convert the letter number between 1 (A) and 26 (Z), that part is working, my issue is how to assign the printf output to a variable:LetterNumber=10 printf "\x$(printf %x $((${LetterNumber}+64)))" $ J #The problem, how to assign printf output (J in this... (8 Replies)
Discussion started by: Ophiuchus
8 Replies

8. Shell Programming and Scripting

Number lines of file and assign variable to each number

I have a file with a list of config files numbered on the lefthand side 1-300. I need to have bash read each lines number and assign it to a variable so it can be chosen by the user called by the script later. Ex. 1 some data 2 something else 3 more stuff which number do you... (1 Reply)
Discussion started by: glev2005
1 Replies

9. Shell Programming and Scripting

read contents of a file with serveral lines & assign it to a variable

Hi All I have a file for ex .log file which contain several lines within it. I have to read that file contents & assing that to a variable. (2 Replies)
Discussion started by: satyam.sumit
2 Replies

10. Shell Programming and Scripting

Assign value to a variable in a parameter file

Hi, I have a parameter file and it contains following items $ cat TransactionParams From_Date_Parm=2005-02-25 To_Date_Parm=2005-05-25 Extract_Root_Parm=/detld1/etl/ascential/Ascential/DataStage/Projects/CTI_London/IAM Extract_Type_Parm=Transaction EDW_Database_Parm=hdw_erks... (2 Replies)
Discussion started by: gopskrish
2 Replies
Login or Register to Ask a Question