parse a token from output

August 10, 2009 at 13:46:48
Specs: Windows 7
There is mencoder for windows which do an output like this:
...
Pos: 0.0s 2f ( 0%) 0.00fps Trem: 0min 0mb A-V:0.000 [0:0]
Pos: 0.1s 3f ( 0%) 0.00fps Trem: 0min 0mb A-V:0.000 [0:0]
Pos: 0.1s 4f ( 0%) 0.00fps Trem: 0min 0mb A-V:0.000 [0:0]
Pos: 0.2s 5f ( 0%) 0.00fps Trem: 0min 0mb A-V:0.000 [0:0]
Pos: 0.2s 6f ( 0%) 0.00fps Trem: 0min 0mb A-V:0.000 [0:0]
Pos: 0.2s 7f ( 0%) 0.00fps Trem: 0min 0mb A-V:0.000 [0:0]
Pos: 0.3s 8f ( 0%) 0.00fps Trem: 0min 0mb A-V:0.000 [0:0]
Pos: 0.3s 9f ( 0%) 0.00fps Trem: 0min 0mb A-V:0.000 [0:0]
Pos: 0.4s 10f ( 0%) 0.00fps Trem: 0min 0mb A-V:0.000 [0:0]
...
The strange thing is, U can see here after "]" at end of a line, that mencoder do a supposed "\n\r" and make a new line. But no, there is no new line, the whole output is like this:
...
Pos: 0.0s 2f ( 0%) 0.00fps Trem: 0min 0mb A-V:0.000 [0:0]Pos: 0.1s 3f ( 0%) 0.00fps Trem: 0min 0mb A-V:0.000 [0:0]Pos: 0.1s 4f ( 0%) 0.00fps Trem: 0min 0mb A-V:0.000 [0:0]Pos: 0.2s 5f ( 0%) 0.00fps Trem: 0min 0mb A-V:0.000 [0:0]Pos: 0.2s 6f ( 0%) 0.00fps Trem: 0min 0mb A-V:0.000 [0:0]Pos: 0.2s 7f ( 0%) 0.00fps Trem: 0min 0mb A-V:0.000 [0:0]Pos: 0.3s 8f ( 0%) 0.00fps Trem: 0min 0mb A-V:0.000 [0:0]Pos: 0.3s 9f ( 0%) 0.00fps Trem: 0min 0mb A-V:0.000 [0:0]Pos: 0.4s 10f ( 0%) 0.00fps Trem: 0min 0mb A-V:0.000 [0:0]
...
So I need parsing the token after "Term:", the "0min" which is the time ETA indicator. (the "( 0%)" token would be nice too)
I have "for" batch routines, with find or findstr, but all do that process lines line by line. So I got this strange output with "Pos: .... blah, blah" lines but no "newline sign" between them.
How can I do this with a batch script on Win 7? Parse the ETA token from this lines?

If U understand the whole thing: I started mencoder to encode a film with separated cmd window, make it redirect the output to a temp file. I need to read this temp file in my main cmd window and batch program and need that token which I explained to be parsed to get the mencoder process % or ETA.

p.s.: I checked the "not new line" code with hex editor in the output text file, and there is only just $0D between "Pos: ... blah, blah" lines, not $0D$0A


See More: parse a token from output

Report •


#1
August 11, 2009 at 15:25:22
Try this bat to split your redirected output file (men-out.txt) into a new file (fixed.txt, susceptible to parsing).

@echo off
setLocal EnableDelayedExpansion
set /p bigline=< "men-out.txt"
set eachline=
set /a x=-1

:loop
set /a x=%x%+1
set char=!bigline:~%x%,1!
set eachline=%eachline%!char!
if !char!==] echo !eachline! >> fixed.txt & set eachline=
if !char!.==. goto :eof
goto loop


Report •

#2
August 12, 2009 at 08:55:50
I suppose, your batch is do the progress char by char of each line. I dont realize, that batch can do this. Very good.

Finally, I got a little program called "minitrue" -> mtr.exe, it's adopted from GNU to windows, which can work with 32, 64 bit winndows 7. So I can process mencoder direct output by piping each "stdout" line to a temp file with correct CR/LF sign at end of lines. This way is quite fast so i can parsing out my data to do what I want.

Thank U very musch for fast respond!

Take care
Pex


Report •

Related Solutions


Ask Question