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.
How to count occurrences of a word in all the files of a directory? But with count incremented only once per word per file
So what you want is the number of files that contain that word. Easy:
grep -l word *|wc -l
It is already case-sensitive. Do you mean case-insensitive? –
Vinegar
But if a directory has both directories and files within itself, this command applies only to the files in it but not its child directories recursively, right? Is there a way to count words in this scenario too? –
Marela
© 2022 - 2024 — McMap. All rights reserved.
grep -l "\bword\b" *|wc -l
, right? Correct me if I'm wrong. – Marela