如何计算一个单词在目录的所有文件中出现的次数? [英] How to count occurrences of a word in all the files of a directory?

查看:23
本文介绍了如何计算一个单词在目录的所有文件中出现的次数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试计算整个目录中特定单词的出现次数.这可能吗?

I’m trying to count a particular word occurrence in a whole directory. Is this possible?

例如,有一个包含 100 个文件的目录,所有这些文件中都可能包含单词aaa".我如何计算该目录下所有文件中aaa"的数量?

Say for example there is a directory with 100 files all of whose files may have the word "aaa" in them. How would I count the number of "aaa" in all the files under that directory?

我尝试了类似的方法:

 zegrep "xception" `find . -name '*auth*application*' | wc -l 

但它不起作用.

推荐答案

grep -roh aaa .|wc -w

递归地grep当前目录中的所有文件和目录搜索aaa,并仅输出匹配项,而不是整行.然后,只需使用 wc 来计算有多少单词.

Grep recursively all files and directories in the current dir searching for aaa, and output only the matches, not the entire line. Then, just use wc to count how many words are there.

这篇关于如何计算一个单词在目录的所有文件中出现的次数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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