Solved Batch Extract multiple lines to log file

April 15, 2013 at 23:00:59
Specs: Windows 64
Hello to all,
I'm creating a batch pull out the mistakes to a log file but are stopped.
in practice I can catch the error string with this:
@echo off
setLocal EnableDelayedExpansion
set SOURCE=%systemdrive%\log.txt
set DESTINATION=%systemdrive%\Error.txt
find /I "CPSE0152E" %source% >>%destination%

But I need to capture even the 2 nexts lines

08.14.22 - CPSE0152E 08.14.47 IS-0001 SS-BSS SSU-BSS SE-NODUMP OPR-UFA0001
08.14.22 - 010000A TRC-ZSC3
08.14.22 - ZSC3 OBJ-zsc3 00000308 LOADSET-BASE

Can you help?


See More: Batch Extract multiple lines to log file

Report •

✔ Best Answer
April 26, 2013 at 14:32:36
I'm thinking what is wanted is to make it "repeatable" as a loop. Here's M2's idea modified to be repetetive for multiple instances of CPSE...
::====== begin batchscript
@echo off & setlocal enabledelayedexpansion
set lines=
for /f "tokens=1* delims=[]" %%a in ('find /n /i "CPSE0152E"^<some.log') do (
set lines=!lines! %%a
)

for /f "tokens=1* delims=[]" %%a in ('find /i /n /v ""^<some.log') do (
for %%c in (%lines%) do (
set /a z=%%c+2
for /L %%d in (%%c 1 !z!) do (
if %%a equ %%d echo %%b
)
)
)>>logerrs
::==== end batch



#1
April 15, 2013 at 23:05:05
Sorry, The next 2 lines are variable lines I can not find a fixed string but only the line +2

Report •

#2
April 15, 2013 at 23:42:15
:: ===== script starts here ===============
::
:: sisma.bat 2013-04-16 13:21:56.37
@echo off > NEWFILE & setLocal enableDELAYedeXpansioN

for /f "tokens=1* delims=[]" %%a in ('find /n /i "CPSE0152E" ^< some.log') do (
set I=%%a
)
set/a J=!I!+1
set/a K=!I!+2
set LINES=!I! !J! !K!

for /f "tokens=1* delims=[]" %%a in ('find /n /v "" ^< some.log') do (
for %%z in (!LINES!) do (
if %%a equ %%z >> newfile echo.%%b
)
)
::====== script ends here =================

=====================
M2 Golden-Triangle


Report •

#3
April 18, 2013 at 03:36:39
Many thanks Meachanix!! Superb!
just another question, the batch intercept 22 entry
How can i do to append all?

Report •

Related Solutions

#4
April 18, 2013 at 04:43:53
Not clear. Post a useful chunk of the file and say what output is needed.

=====================
M2 Golden-Triangle


Report •

#5
April 25, 2013 at 12:13:26
ok this is the final result... but your suggestion pulls out only one

00.47.15 - CPSE0152E 00.49.14 IS-0002 SS-BSS SSU-BSS SE-NODUMP OPR-UFA0001
00.47.15 - 010000A TRC-ZSC3
00.47.15 - ZSC3 OBJ-zsc3 00000308 LOADSET-BASE

07.30.07 - CPSE0152E 07.32.05 IS-0001 SS-BSS SSU-BSS SE-NODUMP OPR-UFA0001
07.30.07 - 010000A TRC-ZSC3
07.30.07 - ZSC3 OBJ-zsc3 00000308 LOADSET-BASE

08.41.33 - CPSE0152E 08.43.31 IS-0001 SS-BSS SSU-BSS SE-NODUMP OPR-UFA0001
08.41.33 - 010000A TRC-ZSC3
08.41.33 - ZSC3 OBJ-zsc3 00000308 LOADSET-BASE
08.42.01 -

09.07.41 - CPSE0152E 09.09.40 IS-0001 SS-BSS SSU-BSS SE-NODUMP OPR-UFA0001
09.07.41 - 010000A TRC-ZSC3
09.07.42 - ZSC3 OBJ-zsc3 00000308 LOADSET-BASE

09.14.10 - CPSE0152E 09.16.07 IS-0002 SS-BSS SSU-BSS SE-NODUMP OPR-UFA0001
09.14.10 - 010000A TRC-ZSC3
09.14.10 - ZSC3 OBJ-zsc3 00000308 LOADSET-BASE


Report •

#6
April 26, 2013 at 00:56:46
That's the output. Where's the FILE?

=====================
M2 Golden-Triangle


Report •

#7
April 26, 2013 at 14:32:36
✔ Best Answer
I'm thinking what is wanted is to make it "repeatable" as a loop. Here's M2's idea modified to be repetetive for multiple instances of CPSE...
::====== begin batchscript
@echo off & setlocal enabledelayedexpansion
set lines=
for /f "tokens=1* delims=[]" %%a in ('find /n /i "CPSE0152E"^<some.log') do (
set lines=!lines! %%a
)

for /f "tokens=1* delims=[]" %%a in ('find /i /n /v ""^<some.log') do (
for %%c in (%lines%) do (
set /a z=%%c+2
for /L %%d in (%%c 1 !z!) do (
if %%a equ %%d echo %%b
)
)
)>>logerrs
::==== end batch


Report •

#8
April 26, 2013 at 23:54:22
OP, don't wait another week. My attention span ain't what it usta be.

=====================
M2 Golden-Triangle


Report •

#9
May 8, 2013 at 17:32:12
Mechanix 2Go sorry !!

the original file have one or more entry with errors, in the final log file needs to be all errors lines but your script extract only one error entry and don't append other error..


Report •

#10
May 9, 2013 at 05:24:20
Mechanix2Go (April 27): [D]on't wait another week.
sisma77 (May 8): [S]orry !!
*snerk*

How To Ask Questions The Smart Way


Report •

#11
May 9, 2013 at 05:40:41
Still no clarity.

I lost interest.

=====================
M2 Golden-Triangle


Report •

#12
May 9, 2013 at 08:02:43
c:\testing>type some.log
00.47.15 - CPSE0152E 00.49.14 IS-0002 SS-BSS SSU-BSS SE-NODUMP OPR-UFA0001
00.47.15 - 010000A TRC-ZSC3
00.47.15 - ZSC3 OBJ-zsc3 00000308 LOADSET-BASE

07.30.07 - CPSE0152E 07.32.05 IS-0001 SS-BSS SSU-BSS SE-NODUMP OPR-UFA0001
07.30.07 - 010000A TRC-ZSC3
07.30.07 - ZSC3 OBJ-zsc3 00000308 LOADSET-BASE

08.41.33 - SKIP_ME 08.43.31 IS-0001 SS-BSS SSU-BSS SE-NODUMP OPR-UFA0001
08.41.33 - 010000A TRC-ZSC3
08.41.33 - ZSC3 OBJ-zsc3 00000308 LOADSET-BASE
08.42.01 -

09.07.41 - CPSE0152E 09.09.40 IS-0001 SS-BSS SSU-BSS SE-NODUMP OPR-UFA0001
09.07.41 - 010000A TRC-ZSC3
09.07.42 - ZSC3 OBJ-zsc3 00000308 LOADSET-BASE

09.14.10 - CPSE0152E 09.16.07 IS-0002 SS-BSS SSU-BSS SE-NODUMP OPR-UFA0001
09.14.10 - 010000A TRC-ZSC3
09.14.10 - ZSC3 OBJ-zsc3 00000308 LOADSET-BASE


c:\testing>perl -ne "BEGIN{$/=''} print if /CPSE0152E/" some.log

00.47.15 - CPSE0152E 00.49.14 IS-0002 SS-BSS SSU-BSS SE-NODUMP OPR-UFA0001
00.47.15 - 010000A TRC-ZSC3
00.47.15 - ZSC3 OBJ-zsc3 00000308 LOADSET-BASE

07.30.07 - CPSE0152E 07.32.05 IS-0001 SS-BSS SSU-BSS SE-NODUMP OPR-UFA0001
07.30.07 - 010000A TRC-ZSC3
07.30.07 - ZSC3 OBJ-zsc3 00000308 LOADSET-BASE

09.07.41 - CPSE0152E 09.09.40 IS-0001 SS-BSS SSU-BSS SE-NODUMP OPR-UFA0001
09.07.41 - 010000A TRC-ZSC3
09.07.42 - ZSC3 OBJ-zsc3 00000308 LOADSET-BASE

09.14.10 - CPSE0152E 09.16.07 IS-0002 SS-BSS SSU-BSS SE-NODUMP OPR-UFA0001
09.14.10 - 010000A TRC-ZSC3
09.14.10 - ZSC3 OBJ-zsc3 00000308 LOADSET-BASE


Report •

Ask Question