Search code examples
stringfindstr

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


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


Solution

  • 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.