问题
So I want to be able to search for the string "[ FAILED ]" and the string "." that are both on the same line inside of a text file. How would I do this?
I tried this:
FINDSTR /C:"[ FAILED ]" /C:"." output_.txt
but it produces lines that contain either of the strings. If possible I also want to be able to exclude any lines that contain numbers from my finds.
回答1:
I have answered my own question using piping and coming up with the following command:
FINDSTR /C:"[ FAILED ]" output_.txt | FINDSTR /C:"." | FINDSTR /V [0-9]
回答2:
It is possible to get the answer with a single FINDSTR using two regex search strings.
One string looks for [ FAILED ] followed by ., and the other looks for . followed by [ FAILED ]. Note that . and [ literals must be escaped, and escaping the ] literal isn't necessary, but it makes the intent more obvious.
findstr /r /c:"\[ FAILED \].*\." /c:"\..*\[ FAILED \]" output.txt
I'm not sure which is faster - one FINDSTR with two search strings, or two FINDSTR joined by a pipe, with one search string each.
来源:https://stackoverflow.com/questions/32128009/how-to-use-findstr-to-search-for-multiple-strings-in-one-line