How to get "wc -l" to print just the number of lines without file name?

PoGibas picture PoGibas · Apr 20, 2012 · Viewed 162.5k times · Source
wc -l file.txt

outputs number of lines and file name.

I need just the number itself (not the file name).

I can do this

 wc -l file.txt | awk '{print $1}'

But maybe there is a better way?

Answer

Norman Ramsey picture Norman Ramsey · Apr 20, 2012

Try this way:

wc -l < file.txt