我已经组装了一个批处理脚本(当然是在stackoverflow上找到的部分),它在日志文件中搜索“ERROR:”字符串并写下以前的非错误行。
setlocal EnableDelayedExpansion
set numbers=
for /F "delims=:" %%a in ('findstr /I /N /C:"ERROR:" %MainLog%') do (
set /A before=%%a-1, after=%%a+1
set "numbers=!numbers!!before!: !before!: "
)
(for /F "tokens=1* delims=:" %%a in ('findstr /N "^" %MainLog% ^|findstr /B "%numbers%" ^| findstr /V /C:"ERROR:"') do echo %%b) > %outputFile%
这个想法是从这个日志文件:
07:19:44 Generating SOFTWARE report number 1
07:19:44 Generating SOFTWARE report number 2
07:19:44 Generating SOFTWARE report number 3
07:37:56 ERROR: Could not find P(reportsWizard_CloseX.png) S: 0.7 T: 72,-2 within 100 screen searches
07:47:08 ERROR: Could not find P(reusablePickObject_quick_search.png) S: 0.7 T: -10,0 within 100 screen searches
07:56:24 ERROR: Could not find P(reusablePickObject_ClickStatus.png) S: 0.7 T: -37,17 within 100 screen searches
08:05:54 ERROR: Could not find P(reusablePickObject_ClickStatus.png) S: 0.7 T: -37,17 within 100 screen searches
07:19:44 Generating SOFTWARE report number 4
07:19:44 Generating SOFTWARE report number 5
07:19:44 Generating SOFTWARE report number 6
07:37:56 ERROR: Could not find P(reportsWizard_CloseX.png) S: 0.7 T: 72,-2 within 100 screen searches
07:47:08 ERROR: Could not find P(reusablePickObject_quick_search.png) S: 0.7 T: -10,0 within 100 screen searches
07:19:44 Generating SOFTWARE report number 7
07:19:44 Generating SOFTWARE report number 8
07:19:44 Generating SOFTWARE report number 9
它只提取行:
07:19:44 Generating SOFTWARE report number 3
07:19:44 Generating SOFTWARE report number 6
它可能不完美,但它到目前为止工作,现在我想改进它,以计算在这样的非错误日志下写入多少错误日志:
07:19:44 Generating SOFTWARE report number 3 (4 ERRORS)
07:19:44 Generating SOFTWARE report number 6 (2 ERRORS)
就是这样......所以基本上,我只需要添加带有错误计数的括号,我不知道该怎么做,是否值得努力,甚至可以批量执行。 谢谢你的想法。
答案 0 :(得分:0)
另一种方法:查看每一行,计算连续的错误行并在计数器错误之前打印行(代码中的解释):
if !count! gtr 0
删除Secret Text
,您将获得每个报告,其中包含错误数