我需要在Windows中做一个递归的grep,在Unix/Linux中就像这样:

grep -i 'string' `find . -print`

或者更可取的方法:

find . -print | xargs grep -i 'string'

我只能使用cmd.exe,所以我只有Windows内置命令。不幸的是,我无法在这个服务器上安装Cygwin或任何第三方工具,如UnxUtils。我甚至不确定我能不能安装PowerShell。只使用cmd.exe内置程序(Windows 2003 Server)有什么建议吗?


当前回答

如果您安装了Perl,您可以使用ack,可以在http://beyondgrep.com/上获得。

其他回答

我推荐一个很棒的工具:

原生Unix utils:

http://unxutils.sourceforge.net/ http://en.wikipedia.org/wiki/UnxUtils

只需解压缩它们,并将该文件夹放入PATH环境变量中,瞧!:)

工作就像一个魅力,有很多比只有grep;)

如果您安装了Perl,您可以使用ack,可以在http://beyondgrep.com/上获得。

在src文件夹内递归搜索导入单词:

> findstr /s import .\src\*

Select-String最适合我。这里列出的所有其他选项(比如findstr)都不能处理大文件。

这里有一个例子:

select-string -pattern "<pattern>" -path "<path>"

注意:这需要Powershell

for /f %G in ('dir *.cpp *.h /s/b') do  ( find /i "what you search"  "%G") >> out_file.txt