Count files matching pattern using GREP
I am on a windows server and installed GREP to win. I need to count the number of filenames that match (or don't match) a particular pattern. I don't need all the filenames listed, I just want the total number of matches. The tree structure I will be looking for is quite large, so I would like to keep as much processing as possible.
I'm not very familiar with grep, but it looks like I can use the -l option to find filenames that match a given pattern. So, for example, I could use
$grep -l -r this *.doc*
to find all MS files in the current folder and all child folders. Then this will return me a list of all these files. I don't want to list, I just want to count the number of items found. Is this possible with GREP ... or some other tool?
thank!
source to share
On linux, you will use
grep -l -r this .doc | wc -l
to get the number of printed lines
Although -r.doc does not search for all text files, you must use --include "* doc".
And if you don't have wc, you can use grep again to count the number of matches:
grep -l -r --include "*doc" this . | grep -c .
source to share