1

是否可以搜索字符串列表(100+),例如在文本文件中并使用诸如 findstr 之类的命令来识别哪些文件包含任何字符串?还是有更好的选择(在 Windows 上)?

4

1 回答 1

1

可能,从我发现的 findstr 帮助中:

/G:file 从指定文件中获取搜索字符串(/ 代表控制台)。

/S 在当前目录和所有子目录中搜索匹配的文件。

所以:

C:\Temp>copy con strings.txt
test
test1
test2
^Z
    1 file(s) copied.

我创建(复制 con 将我带回来)3 个文件 test.txt test1.txt 和 test2.txt 并将我们从 strings.txt 获得的字符串放入相应的文件中,然后运行以下命令:

C:\Temp>findstr /S /G:strings.txt *.txt
strings.txt:test
strings.txt:test1
strings.txt:test2
test.txt:test
test1.txt:test1
test2.txt:test2

它确实找到了它们,甚至从源文件 strings.txt 中找到了所有三个。

于 2011-05-06T21:08:29.103 回答