How to count occurrences of a word in all the files of a directory? But with count incremented only once per word per file

匆匆过客 提交于 2019-12-11 02:27:23

问题


This question is an additional constraint on this this question. I wanted achieve the word count by avoiding multiple counts for that same word in the same file? Eg : if word "aaa" appears in "file1.txt" 10 times, but count should increase only by 1 but not 10 & so on for other files too within a directory.


回答1:


So what you want is the number of files that contain that word. Easy:

grep -l word *|wc -l


来源:https://stackoverflow.com/questions/19869272/how-to-count-occurrences-of-a-word-in-all-the-files-of-a-directory-but-with-cou

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!