wc -l


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting wc -l
# 1  
Old 02-19-2008
wc -l

Hi,

This might be a very basic question but i am begineer with UNIX. The output of wc -l gives the line count along with the filename.

$ wc -l compare_output.dat > test.dat
$ more test.dat
10 compare_output.dat

I just want the digit 10 in this sceniro. Can anyone plez help me on this

Thanks in advance
# 2  
Old 02-19-2008
Quote:
Originally Posted by fristy_guy
$ wc -l compare_output.dat > test.dat
$ more test.dat
10 compare_output.dat
I just want the digit 10 in this sceniro. Can anyone plez help me on this
Code:
wc -l <compare_output.dat >test.dat

# 3  
Old 02-19-2008
Quote:
Originally Posted by vino
Code:
wc -l <compare_output.dat >test.dat


Vino,

I am not quite getting what you are trying to say i have already redirected the output to test.dat. When we do a more of test.dat it has the line count followed by the filename/filepath. What i desire is only the count and excluding the trailing filename/filepath since i want it to be assigned to a varaible for further operation
# 4  
Old 02-19-2008
Hi,

Have you tried the above code? It will give you what you expect

Code:
wc -l < filename

will give only the count of lines in the file.


Regards,
Chella
# 5  
Old 02-19-2008
Quote:
Originally Posted by fristy_guy
Vino,

I am not quite getting what you are trying to say i have already redirected the output to test.dat. When we do a more of test.dat it has the line count followed by the filename/filepath. What i desire is only the count and excluding the trailing filename/filepath since i want it to be assigned to a varaible for further operation
Look carefully and see the file redirection <
Code:
wc -l <compare_output.dat >test.dat

# 6  
Old 02-19-2008
Tools actual code and storage of variable

Code:
> wcl=$(cat find_file.txt | wc -l)
> echo $wcl
4

# 7  
Old 02-19-2008
The below code also works

Quote:
VAR=$(wc -l filename | cut -d" " -f 1); echo $VAR
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question