I want to search for files which contain "foo" and "bar". The search strings may or may not be in the same line and "foo" might be before or after "bar".
What I did:
findstr /P /S /I /M "foo" C:\dir\to\search\*.txt > C:\tmp\results.txt
This gives a file with a list of files, one file per line.
Now I tried different things
findstr /I /M "bar" /F:C:\tmp\results.txt
This prints an error "FINDSTR: /F:C:\tmp\results.txt can't be opened"
switching searchstring and filelist like so findstr /I /M /F:C:\tmp\results.txt "bar" this prints "FINDSTR ■C can't be opened" once and then "FINDSTR: can't be opened" as often as there are lines in the results.txt
How is this supposed to work, and is there another (better) way to archive the goal?
After getting no reply here, I asked chatGPT, it clearly mixed up the /G and /F parameters, but in the end I tried the exact same thing I already tried a few dozen times 3 weeks ago. But now it works. I have no clue why.
What I do now:
findstr /P /S /I /M "foo" C:\dir\to\search\* > C:\tmp\results.txt
findstr /I /M /F:C\tmp\results.txt "bar"
this works. To me it looks exactly the same to what I did in my 2nd try mentioned in the question.
Hopefully someone has an idea what could have been wrong back then. But for now I am happy it finally works.