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

StackOverflow https://stackoverflow.com/questions/19869272

문제

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.

도움이 되었습니까?

해결책

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

grep -l word *|wc -l
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top