shell 统计行数

统计指定

cat logs* | grep content  |wc -l

cat logs* | grep -c content

分析:

wc: word count,加参数为统计行数

grep -c 用统计查找后结果的行数统计

例子,文件test

hvg
hgvhjgh
hhhjh
jjjhvvg
hhhhjh
haha
haha
haha
hghh
hvhjjjj

grep统计行数

$ cat test | grep -c haha
3

wc统计行数

$ cat test | grep haha |wc -l
3

 

比如查询本机连接 80 端口的连接数,可以这样:

netstat -an | grep '80' | grep -v '0.0.0.0' | wc -l

其中 grep -v 是去除不包含0.0.0.0的行

wc -l 是按行统计

这样就可以直接显示结果:42行。

参考:

https://blog.csdn.net/qq_21514303/article/details/88220284

 

原文地址:https://www.cnblogs.com/sea-stream/p/11271561.html