请帮助语法查找字符串以搜索带字符串的paragrah开头并以另一个字符串结束。 例如:支持成功处理成员ID为1234的文件。在这里,我想搜索某些行以成员开头,并以成功处理结束。这里我使用下面的代码(供参考)。 请告诉我任何困惑
for /f "delims=" %%A in ('
findstr /B "member " /E "processed successfully." abc.log
') do set "check=True"
答案 0 :(得分:1)
Findstr
command使用正则表达式(搜索文本模式)
findstr /R "^member\ .*processed\ successfully\.$" abc.log
或没有正则表达式:管道findstr
输出到另一个findstr
,如下所示:
findstr /B /C:"member " abc.log | findstr /E /C:"processed successfully."
注意:如果在for /F
loop中使用|
管道字符,则需要对管道命令的结果进行转义,如下所示:
for /f "delims=" %%A in ('
findstr /B /C:"member " abc.log ^| findstr /E /C:"processed successfully."
') do set "check=True"
正则表达式:
FINDSTR
对正则表达式的支持是有限且非标准的,只有以下元字符是 支持:. Wildcard: any character * Repeat: zero or more occurances of previous character or class ^ Line position: beginning of line $ Line position: end of line [class] Character class: any one character in set [^class] Inverse class: any one character not in set [x-y] Range: any characters within the specified range \x Escape: literal use of metacharacter x \<xyz Word position: beginning of xyz\> Word position: end of word