How to count lines in a document?

2019-01-05 06:25发布

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?

19条回答
成全新的幸福
2楼-- · 2019-01-05 07:12

If you want to check the total line of all the files in a directory ,you can use find and wc:

find . -type f -exec wc -l {} +
查看更多
劫难
3楼-- · 2019-01-05 07:12

I just made a program to do this ( with node )

npm install gimme-lines
gimme-lines verbose --exclude=node_modules,public,vendor --exclude_extensions=html

https://github.com/danschumann/gimme-lines/tree/master

查看更多
我想做一个坏孩纸
4楼-- · 2019-01-05 07:13
cat file.log | wc -l | grep -oE '\d+'
  • grep -oE '\d+': In order to return the digit numbers ONLY.
查看更多
啃猪蹄的小仙女
5楼-- · 2019-01-05 07:14

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
查看更多
▲ chillily
6楼-- · 2019-01-05 07:14

The tool wc is the "word counter" in UNIX and UNIX-like operating systems, you can also use it to count lines in a file, by adding the -l option, so wc -l foo will count the number of lines in foo. You can also pipe output from a program like this: ls -l | wc -l, which will tell you how many files are in the current directory.

查看更多
劳资没心,怎么记你
7楼-- · 2019-01-05 07:15

I've been using this:

cat myfile.txt | wc -l

I prefer it over the accepted answer because it does not print the filename, and you don't have to use awk to fix that. Accepted answer:

wc -l myfile.txt

But I think the best one is GGB667's answer:

wc -l < myfile.txt

I will probably be using that from now on. It's slightly shorter than my way. I am putting up my old way of doing it in case anyone prefers it. The output is the same with those two methods.

查看更多
登录 后发表回答