How to only get the number of lines of a file
Try this
wc -l < sample.txt
wc
doesn't print out the filename if it reads the file through standard input. The <
feeds the file via standard input.
Other single commands to get the number of lines in a file without filename.
sed
:
$ sed -n '$=' filename
awk
:
$ awk 'END{print NR}' filename
If you want to strip the whitespace out too, use sed
.
wc -l < file | sed 's/ //g'