My requirement goes this way. I am trying to extract the records in between that satisfies some condition from a file. The input file is as follows.
Input File:-
+++ EXTR MSG - PROGRA1 /- KEY - 000000000000259 20141126 20141204 E
I EXTRACTION COMPLETE
I
I 259 EXTRACTION COMPLETE
+++
+++ EXTR MSG - PROGRA1 /- KEY - 100000000000063 20141126 20141204 E
E MESGR1 ERROR EXTRACTING THE KEY RECORD
E MESGR1 ERROR EXTRACTING THE KEY RECORD
E MESGR1 EXTRACTION COMPLETE
E MESGR1 ERROR EXTRACTING THE KEY RECORD
I MESGR1 LOAN ERROR EXTRACTING THE KEY RECORD
I LOAN
I 63 EXTRACTION COMPLETE
+++
+++ EXTR MSG - PROGRA1 /- KEY - 000000000000298 20141126 20141204 E
I EXTRACTION COMPLETE
I
I 298 EXTRACTION COMPLETE
+++
+++ EXTR MSG - PROGRA1 /- KEY - 200000000000989 20141126 20141204 E
E MESGR1 ERROR EXTRACTING THE KEY RECORD
E MESGR1 ERROR EXTRACTING THE KEY RECORD
E MESGR1 EXTRACTION COMPLETE
E MESGR1 ERROR EXTRACTING THE KEY RECORD
I MESGR1 LOAN ERROR EXTRACTING THE KEY RECORD
I LOAN
I 989 EXTRACTION COMPLETE
+++
I EXTRACTION COMPLETE
I
I 259 EXTRACTION COMPLETE
+++
+++ EXTR MSG - PROGRA1 /- KEY - 100000000000063 20141126 20141204 E
E MESGR1 ERROR EXTRACTING THE KEY RECORD
E MESGR1 ERROR EXTRACTING THE KEY RECORD
E MESGR1 EXTRACTION COMPLETE
E MESGR1 ERROR EXTRACTING THE KEY RECORD
I MESGR1 LOAN ERROR EXTRACTING THE KEY RECORD
I LOAN
I 63 EXTRACTION COMPLETE
+++
+++ EXTR MSG - PROGRA1 /- KEY - 000000000000298 20141126 20141204 E
I EXTRACTION COMPLETE
I
I 298 EXTRACTION COMPLETE
+++
+++ EXTR MSG - PROGRA1 /- KEY - 200000000000989 20141126 20141204 E
E MESGR1 ERROR EXTRACTING THE KEY RECORD
E MESGR1 ERROR EXTRACTING THE KEY RECORD
E MESGR1 EXTRACTION COMPLETE
E MESGR1 ERROR EXTRACTING THE KEY RECORD
I MESGR1 LOAN ERROR EXTRACTING THE KEY RECORD
I LOAN
I 989 EXTRACTION COMPLETE
+++
I want to retrieve only the records that has error message's (i.e. the lines with character "E" in 7th position ) along with the line that contains "KEY" information. The output should be as follows.
Output File:-
+++ EXTR MSG - PROGRA1 /- KEY - 100000000000063 20141126 20141204 E
E MESGR1 ERROR EXTRACTING THE KEY RECORD
E MESGR1 ERROR EXTRACTING THE KEY RECORD
E MESGR1 EXTRACTION COMPLETE
E MESGR1 ERROR EXTRACTING THE KEY RECORD
+++ EXTR MSG - PROGRA1 /- KEY - 200000000000989 20141126 20141204 E
E MESGR1 ERROR EXTRACTING THE KEY RECORD
E MESGR1 ERROR EXTRACTING THE KEY RECORD
E MESGR1 EXTRACTION COMPLETE
E MESGR1 ERROR EXTRACTING THE KEY RECORD
I tried using the below sort cards first by assigning the sequence number to it in one file.
INREC IFTHEN=(WHEN=INIT,
OVERLAY=(72:SEQNUM,2,ZD,
RESTART=(1,2)))
SORT FIELDS=COPY
OVERLAY=(72:SEQNUM,2,ZD,
RESTART=(1,2)))
SORT FIELDS=COPY
And later extracting the records by grouping them with the below sort card but it didn't work.
INREC IFTHEN=(WHEN=GROUP,
BEGIN=((3,8,CH,EQ,C'+++ EXTR'),AND,(72,2,CH,EQ,C'01')),
END=((7,1,CH,EQ,C'E'),AND,((72,2,CH,EQ,C'02'),OR,
(72,2,CH,EQ,C'03'),OR,
(72,2,CH,EQ,C'04'),OR,
(72,2,CH,EQ,C'05'))),
PUSH=(191:ID=1))
SORT FIELDS=COPY
OUTFIL INCLUDE=(191,1,CH,NE,C' '),BUILD=(1,70,200:X)
BEGIN=((3,8,CH,EQ,C'+++ EXTR'),AND,(72,2,CH,EQ,C'01')),
END=((7,1,CH,EQ,C'E'),AND,((72,2,CH,EQ,C'02'),OR,
(72,2,CH,EQ,C'03'),OR,
(72,2,CH,EQ,C'04'),OR,
(72,2,CH,EQ,C'05'))),
PUSH=(191:ID=1))
SORT FIELDS=COPY
OUTFIL INCLUDE=(191,1,CH,NE,C' '),BUILD=(1,70,200:X)
Can someone kindly help me out?
Thanks in advance!