Page 1 of 1

log parsing

Posted: 07 Aug 2013 01:57
by mor.bas
Hi,
I need a script that get a log file as an input a looking for a line with "fatal error" if he find it print all this line to another output file.
Thanks in advance....

Re: log parsing

Posted: 07 Aug 2013 03:39
by penpen
This might help you:

Code: Select all

@echo off
setlocal
set "logFile=test.txt"
set "outFile=out.txt"
(
   for /F "tokens=* delims=" %%a in ('findstr /C:"fatal error" "%logFile%"') do echo(%%a
) > "%outFile%"
endlocal
goto :eof

penpen

Edit: Corrected the code.

Re: log parsing

Posted: 07 Aug 2013 04:21
by mor.bas
Hi,
Thanks i did'nt understand 100% what it's print in th output file beacuse i saw there also line with warning indside.
I just want to print the line with "fatal error" inside.

Re: log parsing

Posted: 07 Aug 2013 04:50
by penpen
Sorry, i have forgotten to use /C:, so i added it to the code above.

Without the C option findstr outputs all lines with "fatal" or "error", the space then is treated as a separator.
When using the C option findstr writes all lines with "fatal error" as one search string to the output.

Btw: If you want to ignore if characters are lower case or upper case, you might use the option /I.

penpen