我有这样的线,我想知道我有多少行。

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

是否有一种方法可以使用linux命令来计算它们?


当前回答

有很多方法。使用wc就是其中之一。

Wc -l文件

其他包括

awk ' end {print NR}'文件

sed -n '$='文件

grep -c ".*" file

其他回答

wc -l <file.txt>

Or

command | wc -l

如果你想要的只是行数(而不是行数和返回的愚蠢的文件名):

wc -l < /filepath/filename.ext

正如前面提到的,这些方法也有效(但由于其他原因,效果较差):

awk 'END{print NR}' file       # not on all unixes
sed -n '$=' file               # (GNU sed) also not on all unixes
grep -c ".*" file              # overkill and probably also slower

我尝试wc -l从文件名中获取行数

要进行更多的过滤,例如想要从文件中计数注释行数,请使用grep '#' Filename.txt | wc -l

echo  "No of files in the file $FILENAME"
wc -l < $FILENAME
echo total number of commented lines
echo $FILENAME
grep '#' $FILENAME | wc -l

我只是做了一个程序来做这个(与节点)

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

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

Wc -l <filename>

这将为您提供输出中的行数和文件名。

Eg.

WC -L 24-11-2019-04-33-01-url_creator.log

输出

63 24-11-2019-04-33-01-url_creator.log

Use

Wc -l <filename>|cut -d\ -f

来获取输出中的行数。

Eg.

url_create .log|cut -d\ -f

输出

63