log parsing

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mor.bas
Posts: 66
Joined: 25 Apr 2012 04:28

log parsing

#1 Post by mor.bas » 07 Aug 2013 01:57

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....

penpen
Expert
Posts: 1999
Joined: 23 Jun 2013 06:15
Location: Germany

Re: log parsing

#2 Post by penpen » 07 Aug 2013 03:39

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.
Last edited by penpen on 07 Aug 2013 04:48, edited 1 time in total.

mor.bas
Posts: 66
Joined: 25 Apr 2012 04:28

Re: log parsing

#3 Post by mor.bas » 07 Aug 2013 04:21

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.

penpen
Expert
Posts: 1999
Joined: 23 Jun 2013 06:15
Location: Germany

Re: log parsing

#4 Post by penpen » 07 Aug 2013 04:50

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

Post Reply