使用grep对大量文件中出现的所有字符串进行计数 [英] Count all occurrences of a string in lots of files with grep

查看:115
本文介绍了使用grep对大量文件中出现的所有字符串进行计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆日志文件。我需要找出所有文件中字符串出现的次数。






file1:1
file2:0
file3:0
...

使用管道我只能得到一个或多个文件:

  grep -c字符串* | grep -v:0 

...
file4:5
file5:1
file6:2
...
code>

我怎样才能得到合计数? (如果它返回 file4:5,file5:1,file6:2 ,我想返回8.)

解决方案

  cat * | grep -c string 


I have a bunch of log files. I need to find out how many times a string occurs in all files.

grep -c string *

returns

...
file1:1
file2:0
file3:0
...

Using a pipe I was able to get only files that have one or more occurrences:

grep -c string * | grep -v :0

...
file4:5
file5:1
file6:2
...

How can I get only the combined count? (If it returns file4:5, file5:1, file6:2, I want to get back 8.)

解决方案

cat * | grep -c string

这篇关于使用grep对大量文件中出现的所有字符串进行计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆