0

I have a log file that i need to go through and find certain strings that do not match and write them out to the log. The code works until the problem arises where it duplicates the last value which is not needed. The code is here:

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% 

and the log file is here:

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,    

The last Value is duplicated. Any help would be appreciated thanks.

1
  • Any reason to not just use grep? Commented Aug 13, 2014 at 18:23

1 Answer 1

1

After the FOR line, the batchfile continues with the next line (:process)

Just put an exit /b or a goto :eof between those two lines:

FOR /F "delims= " %%i IN (%FileName%) DO (SET currentline=%%i & CALL :process)
exit /b        <<<<<< here
:process 
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much.. I thought the FOR loop would stop running after the last line was read.
yes, your FOR loop DOES stop. But then the batchfile continues with the next line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.