我对 Windows 批处理脚本还很陌生,在从文本文件中搜索和提取部分字符串并将其显示出来时遇到了麻烦。下面显示了一些示例数据。
搜索的关键字以学生证号为准,例如:STUD777012
如您能帮忙我将非常感激。
非常感谢。
样本预期输出:
STUD777012,返回代码:0,分析未检测到错误
STUD777293,返回代码:4,分析检测到警告
STUD777086,返回代码:8,分析检测到错误
STUD777099,返回代码:0,分析未检测到错误
样本日志数据:
Compiling STUD777012 to Data Structure
This is prg version 380.10.20
This is StudPrg.exe version 6.24
debug enabled version
StudPrg.exe finished
prg finished with return code: 0
status:
Analysis detected no errors
Compiling STUD777293 to Data Structure
This is prg version 380.10.20
This is StudPrg.exe version 6.24
debug enabled version
StudPrg.exe finished
This is StudPrg.exe version 6.24
debug enabled version
StudPrg.exe finished
prg finished with return code: 4
status:
Analysis detected warnings
Compiling STUD777086 to Data Structure
This is prg version 380.10.20
This is StudPrg.exe version 6.24
debug enabled version
StudPrg.exe finished
This is StudPrg.exe version 6.24
debug enabled version
StudPrg.exe finished
prg finished with return code: 8
status:
Analysis detected errors
答案1
如果你打开文件记事本++并执行正则表达式替换(Ctrl+H):
Find what: Compiling (\w+).*?(return code[^\r\n]*).*?(analysis detected.*?)(\n|$)
Replace with: \1 \2 \3
你应该会得到你想要的。确保你已启用正则表达式并设置“。匹配新行”。例如