How to use findstr to search for multiple strings in one line

本秂侑毒 提交于 2020-01-14 03:35:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!