Problem with processing data from an auto-generated log file.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
VescanR
Posts: 2
Joined: 18 Aug 2016 04:02

Problem with processing data from an auto-generated log file.

#1 Post by VescanR » 18 Aug 2016 04:17

This batch needs to check for a string in a log generated by Passmark Burnin,and take action accordingly.If I run this batch on autolog.log,linie.txt returns me "Echo is off".If I copy(manually) the text from autolog to another .log or .txt file,it works perfectly,but I need the batch to work for the original log.I have tried using type and copy to create a second file with the same text in it but it returns a random word,not the 5th on the 13th row(as I skipped for).PS.I have admin rights and that stuff.



"@echo off
Setlocal EnableDelayedExpansion
for /f "skip=12 tokens=5" %%G in (autolog.log) do set "LINE=%%G"
echo %LINE%>linie.txt
findstr /i "3612QE" linie.txt
if errorlevel 1 goto 2
if errorlevel 0 goto 1
goto end
:1
echo gasit
goto end
:2
echo negasit
goto end
:end
pause"


what could be the problem?
thanks

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Problem with processing data from an auto-generated log file.

#2 Post by aGerman » 18 Aug 2016 04:43

"skip=12" means that the FOR /F loop begins with line 13 but it runs till the end of the file. Variable LINE will be overwritten several times until the end of the file was reached. Thus, the 5th token of the very last line of the file will be saved in this variable. LINE would be not defined if the last line has less than 5 tokens .

Try:

Code: Select all

set "LINE="
for /f "skip=12 tokens=5" %%G in (autolog.log) do if not defined LINE set "LINE=%%G"


Regards
aGerman

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Problem with processing data from an auto-generated log file.

#3 Post by foxidrive » 18 Aug 2016 06:12

This batch needs to check for a string in a log generated by Passmark Burnin,and take action accordingly.


Code: Select all

findstr /i "3612QE" autolog.log >nul && echo Yep, found the word.



That does what you've asked.

VescanR
Posts: 2
Joined: 18 Aug 2016 04:02

Re: Problem with processing data from an auto-generated log file.

#4 Post by VescanR » 18 Aug 2016 23:44

Neither findstr or for /f worked on the auto generated log,but the solution that aGerman gave me worked on a copy of the log.
Thanks everyone for the help.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Problem with processing data from an auto-generated log file.

#5 Post by aGerman » 19 Aug 2016 00:13

Maybe the file has the wrong character encoding. Try using TYPE

Code: Select all

for /f "skip=12 tokens=5" %%G in ('type "autolog.log"') do if not defined LINE set "LINE=%%G"


Regards
aGerman

Post Reply