使用grep计算许多文件中字符串的所有出现次数 [英] Count all occurrences of a string in lots of files with grep

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

问题描述

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

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

grep -c string *

返回

...
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
...

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

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天全站免登陆