计数与GREP匹配模式的文件 [英] Count files matching a pattern with GREP
问题描述
我在一台Windows服务器上安装了GREP for win。我需要计算匹配(或不匹配)特定模式的文件名的数量。我并不需要列出所有的文件名,我只需要总共有多少匹配。我将搜索的树结构相当大,所以我想尽可能地节省处理。
我对grep不是很熟悉,但是它看起来像我可以使用-l选项来搜索匹配给定模式的文件名。因此,例如,我可以使用
$ grep -l -r this * .doc *
搜索当前文件夹和所有子文件夹中的所有MS word文件。然后这将返回给我所有这些文件的列表。我不希望上市,我只是想要找到它的数量。这可能与GREP ...或其他工具?
谢谢!
在Linux上,您可以使用
grep -l -r this .doc | wc -l
得到打印的行数
尽管-r .doc不搜索所有的单词文件,你可以使用--include* doc。
如果你没有wc,你可以再次使用grep来计算匹配的次数:
$ p $ grep -l -r --include* docthis 。 | grep -c。
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 .
这篇关于计数与GREP匹配模式的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!