我有一个日志文件,我需要经历并查找某些不匹配的字符串并将其写入日志。代码一直有效,直到问题出现,它复制了不需要的最后一个值。代码在这里:
echo off
set LogFile=log.out
set LogFileSuccess=logFileSuccess.log
set FileName=testali.log
set lastline=
set currentline=
FOR /F "delims= " %%i IN (%FileName%) DO (SET currentline=%%i & CALL :process)
:process
echo %currentline% | findstr /i "AD\System_ES_COG_RMT_D ??? =====" || echo Name Not Identified: %currentline% >> %LogFile%
,日志文件在这里:
Name Not Identified: 1796 Th:Pseudo Idle - - - -
Name Not Identified: 8572 Th:DynamicConfig Idle - - - -
Name Not Identified: 8008 AD\Kaif,
Name Not Identified: 9332 AD\Mayekar,
Name Not Identified: 5544 AD\Velusamy,
Name Not Identified: 8952 AD\Velusamy,
Name Not Identified: 6460 AD\Velusamy,
Name Not Identified: 1796 Th:Pseudo Idle - - - -
Name Not Identified: 8572 Th:DynamicConfig Idle - - - -
Name Not Identified: 8008 AD\Kaif,
Name Not Identified: 9332 AD\Mayekar,
Name Not Identified: 5544 AD\Velusamy,
Name Not Identified: 8952 AD\Velusamy,
Name Not Identified: 6460 AD\Velusamy,
Name Not Identified: 1796 Th:Pseudo Idle - - - -
Name Not Identified: 8572 Th:DynamicConfig Idle - - - -
Name Not Identified: 8008 AD\Kaif,
Name Not Identified: 9332 AD\Mayekar,
Name Not Identified: 5544 AD\Velusamy,
Name Not Identified: 8952 AD\Velusamy,
Name Not Identified: 6460 AD\Velusamy,
Name Not Identified: 6460 AD\Velusamy,
最后一个值是重复的。任何帮助将不胜感激。
答案 0 :(得分:1)
在FOR
行之后,批处理文件继续下一行(:process
)
只需在这两行之间添加exit /b
或goto :eof
:
FOR /F "delims= " %%i IN (%FileName%) DO (SET currentline=%%i & CALL :process)
exit /b <<<<<< here
:process