I read Chris Maes answer on how to a grep for a particular word in any file/files contained in a directory, and it worked.
But, what is the way of finding the names of the files and the total number of files containing that word ?
Please correct me if I am wrong. Thanks in advance !!
Advertisement
Answer
You just need to add --files-with-matches
to the grep command:
grep -R --files-with-matches --include="*.xml" "pattern" /path/to/dir
If you want the number of matched files you can use pipe the output from the above grep to wc -l
(or you can also pipe it to nl
, so each line will be numbered).