How to count lines in a document?
wc -l <file.txt>
Or
command | wc -l
Use wc
:
wc -l <filename>
This will output the number of lines in <filename>
:
$ wc -l /dir/file.txt
3272485 /dir/file.txt
Or, to omit the <filename>
from the result use wc -l < <filename>
:
$ wc -l < /dir/file.txt
3272485
You can also pipe data to wc
as well:
$ cat /dir/file.txt | wc -l
3272485
$ curl yahoo.com --silent | wc -l
63
To count all lines use:
$ wc -l file
To filter and count only lines with pattern use:
$ grep -w "pattern" -c file
Or use -v to invert match:
$ grep -w "pattern" -c -v file
See the grep man page to take a look at the -e,-i and -x args...
there are many ways. using wc
is one.
wc -l file
others include
awk 'END{print NR}' file
sed -n '$=' file
(GNU sed)
grep -c ".*" file