I have lines like these, and I want to know how many lines I actually have...
09:16:39 AM all 2.00 0.00 4.00 0.00 0.00 0.00 0.00 0.0
Use wc
:
wc -l <filename>
Redirection/Piping the output of the file to wc -l
should suffice, like the following:
cat /etc/fstab | wc -l
which then would provide the no. of lines only.
As others said wc -l
is the best solution, but for future reference you can use Perl:
perl -lne 'END { print $. }'
$.
contains line number and END
block will execute at the end of script.
I saw this question while I was looking for a way to count multiple files lines, so if you want to count multiple file lines of a .txt file you can do this,
cat *.txt | wc -l
it will also run on one .txt file ;)
I know this is old but still: Count filtered lines
My file looks like:
Number of files sent
Company 1 file: foo.pdf OK
Company 1 file: foo.csv OK
Company 1 file: foo.msg OK
Company 2 file: foo.pdf OK
Company 2 file: foo.csv OK
Company 2 file: foo.msg Error
Company 3 file: foo.pdf OK
Company 3 file: foo.csv OK
Company 3 file: foo.msg Error
Company 4 file: foo.pdf OK
Company 4 file: foo.csv OK
Company 4 file: foo.msg Error
If I want to know how many files are sent OK:
grep "OK" <filename> | wc -l
OR
grep -c "OK" filename
wc -l <filename>
This will give you number of lines and filename in output.
Eg.
wc -l 24-11-2019-04-33-01-url_creator.log
Output
63 24-11-2019-04-33-01-url_creator.log
Use
wc -l <filename>|cut -d\ -f 1
to get only number of lines in output.
Eg.
wc -l 24-11-2019-04-33-01-url_creator.log|cut -d\ -f 1
Output
63