Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I would like to recursively search through a parent directory and all sub directories for several separate strings and show the results for each string. For example:

Text To Search For

Foo
Bar
Fizz
Buzz
(list continues for several hundred words)

Results Pane

Foo
  - Found in files x, y, z
Bar
  - Found in files x, y
Fizz
  - Not found in any files
Buzz
  - Found in files y, z

Summary
I have a list of several hundred strings that I will have to search for several times. It is a tedious process to search for individual strings and I'm looking for a way to perform this in a batch process.

Are there any Windows programs that can perform this type of search?

FWIW
I've tried with notepad++ and Visual Studio, but haven't quite found a way to meet the requirements of showing each string as a separate result.

share|improve this question
add comment

3 Answers

The below batch script would do this.

@echo off

for /F %%i in (pattern.txt) do (
echo Files containing %%i
findstr /M /C:%%i /S *.txt
)        

For the case of string not present in any of the files, it does not print the statement you wanted. Instead, it prints an empty list of files. source: Findstr command

share|improve this answer
add comment

The Swiss File Knife has a command "hexfind" which can search any number of patterns in parallel. Create a search pattern file "mypatterns.txt" containing:

/Foo/
/Bar/
/Fizz/
/Buzz/

And to search all files of folder mydir, including all subfolders, type:

sfk hexfind -bylist mypatterns.txt mydir

This will produce a dump of every single hit found, like:

testfiles\Formats\10-dir-list.txt : hit at offset 0x273
>4261724D 75672E68 70700D0A 433A5C73< BarMug.hpp..C:\s 00000273
testfiles\Formats\10-dir-list.txt : hit at offset 0x290
>466F6F42 616E6B5C 42617244 72697665< FooBank\BarDrive 00000290

To list only the filenames containing hits, add option -nodump. This will not produce the exact results pane as you requested, but at least you see where your patterns occur.

If it's a problem to create mypatterns.txt with the // format, you can produce the file from a wordlist.txt like:

sfk filter wordlist.txt -form "/$col1/" +tofile mypatterns.txt
share|improve this answer
    
Thanks for the suggestion of Swiss File Knife and the great example. –  Metro Smurf Jul 13 '12 at 1:44
add comment

Grep is your friend. You can put the patterns to look for into a file called patterns.txt and then run something like the following:

grep -f patterns.txt -r * > ..\results.txt

Edit:

Just came across a question about grep-like things available in Windows. The question and answers cover lots of free and non-free standalone tools and commands built-in to e.g. Powershell.

share|improve this answer
    
Grep would probably work with a bit of wrestling of the switches. Thanks for the suggestion. –  Metro Smurf Jul 13 '12 at 1:45
    
Actually all the switches are shown. '-f filename' is the list of patterns in a file and '-r' is for recursive. The output is very close to what you specified as the goal. The patterns.txt should have a pattern per line. –  jpe Jul 13 '12 at 5:50
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.