I want to count the number of lines in a file using wc -l
but only output the number, without the following space and filename.
Edit from comments: The filename may have numbers in it.
Currently if I do:
wc -l /path/to/file
On a file with 176 lines, the output is:
176 /path/to/file
This is within a bash script, and the resulting number will be assigned as the value of a variable.
I'd use:
Which contarily to
cat file | wc -l
doesn't need to fork a shell and to run another process (and runs faster):(
/tmp/ramdisk/file
was stored in a ramdisk to take I/O and caching out of the equation.)However for small files indeed the difference is neglectable.
Yet another way would be:
Which in my tests performs approximately the same as
<file wc -l
.You can do this with a simple one liner using cat.
cat deluge1.log | wc -l
Answer too simple to require a long drawn out answer.
another cleaner option wc -l filename | awk '{print $1}
example list of entries in a file