3

My problem is to create a batch script file for Windows and iterate through a lot of files and find every file which has a line that contains two specified strings. So if the whole file contains those strings, that's not good enough, they should be at the same line.

For example, I have 5 files which contains the following:

1st: apple:green
2nd: apple
green
3rd: green
apple
4th: apple: yellowgreen
5th: apple: green

It should return the filenames of the first, fourth and fifth file.

Here is what I have:

FINDSTR /s /i /m "apple green" *.txt | FINDSTR "\MyDirectory" >> results.txt

How should I modify this to make it work?

fzl
  • 171
  • 2
  • 10
  • 1
    For more solutions see [How to use findstr to search for multiple strings in one line?](http://stackoverflow.com/questions/32128009/) – Mofi Aug 25 '15 at 11:38
  • You should choose the answer which best fitted your question as the accepted one. – OzW Sep 01 '15 at 10:25

2 Answers2

3
findstr /i /s /m /r /c:"apple.*green" /c:"green.*apple" *.txt
MC ND
  • 69,615
  • 8
  • 84
  • 126
2

EDITED TO WORK WITH FINDSTR

This regex worked for me: "apple.*green green.*apple"

Also, your write to file command with the pipe did not work for me (perhaps I'm missing something). If it doesn't work for you, perhaps this will:

FINDSTR /s /i /m "apple.*green green.*apple" *.txt >> results.txt

OzW
  • 848
  • 1
  • 11
  • 24