Search code examples
linuxbashcommand-linescripting

Count Lines in A Document?


I have a text file, and I like to know the total number of line withou opening it. My document is like these, and I want to know how many lines actually...

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 in Linux Terminal?


Solution

  • 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