Count files matching a pattern with GREP

I am on a windows server, and have installed GREP for win. I need to count the number of file names that match (or do not match) a specific pattern. I don't really need all the filenames listed out, I just need a total count of how many matched. The tree structure that I will be searching is fairly large, so I'd like to conserve as much processing as possible.

I'm not very familiar with grep, but it looks like i can use the -l option to search for file names matching a given pattern. So, for example, I could use

$grep -l -r this *.doc*

to search for all MS word files in the current folder and all child folders. This would then return to me a listing of all those files. i don't want the listing, i just want a count of how many it found. Is this possible with GREP...or another tool?

thanks!


On linux you would use

grep -l -r this .doc | wc -l

to get the number of printed lines

Although -r .doc does not search all word files, you would use --include "*doc" .

And if you do not have wc, you can use grep again, to count the number of matches:

grep -l -r --include "*doc" this . | grep -c .
链接地址: http://www.djcxy.com/p/78320.html

上一篇: 在Python中使用grep仅搜索确切的单词

下一篇: 计数与GREP匹配模式的文件