Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to count lines in a document? [closed]

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.00   94.00 09:16:40 AM  all    5.00    0.00    0.00    4.00    0.00    0.00    0.00    0.00   91.00 09:16:41 AM  all    0.00    0.00    4.00    0.00    0.00    0.00    0.00    0.00   96.00 09:16:42 AM  all    3.00    0.00    1.00    0.00    0.00    0.00    0.00    0.00   96.00 09:16:43 AM  all    0.00    0.00    1.00    0.00    1.00    0.00    0.00    0.00   98.00 09:16:44 AM  all    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00 09:16:45 AM  all    2.00    0.00    6.00    0.00    0.00    0.00    0.00    0.00   92.00 

Is there a way to count them all using linux commands?

like image 694
Alucard Avatar asked Jun 29 '10 00:06

Alucard


People also ask

How do I count the number of lines in a file without opening the file?

If you are in *Nix system, you can call the command wc -l that gives the number of lines in file.

How would you count the lines in a file?

The wc command is used to find the number of lines, characters, words, and bytes of a file. To find the number of lines using wc, we add the -l option. This will give us the total number of lines and the name of the file.

How do I count the number of lines in a file without opening the file in Linux?

Use grep -n string file to find the line number without opening the file.


2 Answers

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 
like image 182
user85509 Avatar answered Sep 21 '22 13:09

user85509


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...

like image 38
Lauro Oliveira Avatar answered Sep 20 '22 13:09

Lauro Oliveira