Help with parsing log file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
sfgman63
Posts: 8
Joined: 26 Nov 2009 01:32

Help with parsing log file

#1 Post by sfgman63 » 04 Dec 2009 20:33

Here is my current code with the help from avery_larry (thank you very much!!!).

Code: Select all

@echo off

set serial=%1

IF EXIST i:\path.info (
   goto SEARCHLOGS
) ELSE (
   net use i: \\10.10.20.30\TestLogs
)

:SEARCHLOGS
cd /d i:\Current_Production\

for /d %%a in (temp2*) do (
   if exist "%%a\results\%serial%_final_run.txt" echo "RUN LOG EXIST" && goto Rest of code
)
goto CHECKVENDOR

:CHECKVENDOR
for /d %%a in (temp2*) do (
   if exist "%%a\VENDOR\results\%serial%_final_run.txt" echo "RUN LOG EXIST" && goto Rest of code
)
echo "RUN LOG DOES NOT EXIST"  && goto Rest of code


What I'm doing is searching for a specific log file using a FOR loop because the directory name changes each day.

The temp2 directories are named in this manner:
temp2_11-30-09
temp2_12-01-09
temp2_12-02-09
temp2_12-03-09
temp2_12-04-09

What I need to do now is parse the log file that was found for this string "FINAL- Overall PASS"

The whole string from the log file looks something like this:

*****************************************************
****-FINAL- Overall PASS: Error1?:0 PASS | Failed:0 |
*****************************************************

Thanks for your help.

jeb
Expert
Posts: 1043
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

#2 Post by jeb » 05 Dec 2009 05:40

Hello sfgman63,

try it with something like


Code: Select all


call :TestFile file1.log
call :TestFile file2.log
goto :eof

:::::::::::::
:TestFile
setlocal
findstr "FINAL- Overall PASS"  "%~1" > NUL
echo %errorlevel%
(
endlocal
goto :eof
)


Findstr will result in an errorlevel 0, if the string is found, else you got 1

Hope it helps
jeb

sfgman63
Posts: 8
Joined: 26 Nov 2009 01:32

#3 Post by sfgman63 » 05 Dec 2009 15:22

jeb, thanks for the quick reply. I put together some quick test code to try it out:

Code: Select all


@echo off
set serial=%1

cd /d c:\temp

for /d %%a in (temp2*) do (
   IF EXIST "C:\temp\%%a\%1_test.txt" echo "RUN LOG EXIST" && call :TestFile C:\temp\%%a\%1_test.txt && goto :eof && goto :eof
)
echo "!!! RUN LOG DOES NOT EXIST !!!"
goto :eof

:::::::::::::
:TestFile
setlocal
findstr /C:"FINAL- Overall PASS" "%~1" > NUL
if %ERRORLEVEL% GEQ 1  ( 
   echo "PASS text not found"
) ELSE (
   echo "PASS text found"
)
endlocal
goto :eof



One thing I can't figure out (this is probably sooo simple) is how to get it out of the call :TestFile function when the "PASS text not found"

This is what I get when I run it and the "PASS text not found".

C:\temp>find_file1 12345
"RUN LOG EXIST"
"PASS text not found"
"!!! RUN LOG DOES NOT EXIST !!!"

Thanks

Post Reply