开发者

Searching for a list of strings using the "findstr" command

开发者 https://www.devze.com 2023-03-04 12:05 出处:网络
Is it possible to search for a list of strings (100+), for example in a text file and using a command such as findstr 开发者_Python百科to identify which files contain any of the strings? Or is there a

Is it possible to search for a list of strings (100+), for example in a text file and using a command such as findstr 开发者_Python百科to identify which files contain any of the strings? Or is there a better alternative (on Windows) ?


Probably, from the findstr help I found:

/G:file Gets search strings from the specified file(/ stands for console).

and

/S Searches for matching files in the current directory and all subdirectories.

so:

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

I created (with copy con brings me back) 3 files test.txt test1.txt and test2.txt and placed the strings we have from strings.txt into the respective files and then ran this command:

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

It indeed found them, and it even found all three from the source file strings.txt.

0

精彩评论

暂无评论...
验证码 换一张
取 消