I have a file with FB 404 and if a condition is met I need to extract 1 record before and 1 record after that condition.
Example Input file has value TENT at 14th position. When this match is found I need to extract 1 record before and 1 record after.
Please let me know if this can be done using SORT.
INPUT:
Code:
=COLS> ----+----1----+----2----+----3----+----4----+----5----+----6----+----7-
****** ***************************** Top of Data *****************************
000001 P0666 1109011644S ABCSAMPLEDEFANOTHERSAMPLE 999999999999999999999996
000002 P0666 1109011644S ABCSAMPLEDEFANOTHERSAMPLE 999999999999999999999996
000003 0666 G TENT S ABCSAMPLEDEFANOTHERSAMPLE 999999999999999999999993
000004 0666 G TENT S ABCSAMPLEDEFANOTHERSAMPLE 888888888888888888888883
000005 P0666 W 1109011644 ABCSAMPLEDEFANOTHERSAMPLE 999999999999999999999993
000006 P0666 W 1109011644 ABCSAMPLEDEFANOTHERSAMPLE 999999999999999999999993
000007 P0666 1109011644TFABCSAMPLEDEFANOTHERSAMPLE 999999999999999999999952
000008 P0666 1109011644S ABCSAMPLEDEFANOTHERSAMPLE KKKKKKKKKKKKKKKKKKKKKKK3
000009 P0666 1109011644 ABCSAMPLEDEFANOTHERSAMPLE IIIIIIIIIIIIIIIIIIIIII93
000010 0666 G TENT S ABCSAMPLEDEFANOTHERSAMPLE UUUUUUUUUUUUUUUUUUUUUU43
000011 P0666 1109011644TFABCSAMPLEDEFANOTHERSAMPLE PPPPPPPPPPPPPPPPPPPPPP92
000012 P0666 1109011644 ABCSAMPLEDEFANOTHERSAMPLE RRRRRRRRRRRRRRRRRRRRRRR3
OUTPUT:
Code:
=COLS> ----+----1----+----2----+----3----+----4----+----5----+----6----+----7-
****** ***************************** Top of Data *****************************
000001 P0666 1109011644S ABCSAMPLEDEFANOTHERSAMPLE 999999999999999999999996
000002 0666 G TENT S ABCSAMPLEDEFANOTHERSAMPLE 999999999999999999999993
000003 0666 G TENT S ABCSAMPLEDEFANOTHERSAMPLE 888888888888888888888883
000004 P0666 W 1109011644 ABCSAMPLEDEFANOTHERSAMPLE 999999999999999999999993
000005 P0666 1109011644 ABCSAMPLEDEFANOTHERSAMPLE IIIIIIIIIIIIIIIIIIIIII93
000006 0666 G TENT S ABCSAMPLEDEFANOTHERSAMPLE UUUUUUUUUUUUUUUUUUUUUU43
000007 P0666 1109011644TFABCSAMPLEDEFANOTHERSAMPLE PPPPPPPPPPPPPPPPPPPPPP92
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
In your example you have a TENT followed by a TENT. In the output you only have one record before the first TENT and one record after the second TENT.
Are you saying you want one before and after unless after/before is TENT as well? So if you had three TENTs consecutively, the output would be non-TENT, TENT, TENT, TENT, non-TENT?
Are you saying you want one before and after unless after/before is TENT as well? So if you had three TENTs consecutively, the output would be non-TENT, TENT, TENT, TENT, non-TENT?
Exactly. Sorry I should have given more details. I want to check these records (1 before TENT and 1 after TENT). One more thing. In the INPUT file there will not be more than 2 TENTS consecutively.
P0666 1109011644S ABCSAMPLEDEFANOTHERSAMPLE 999999999999999999999996
0666 G TENT S ABCSAMPLEDEFANOTHERSAMPLE 999999999999999999999993
0666 G TENT S ABCSAMPLEDEFANOTHERSAMPLE 888888888888888888888883
P0666 W 1109011644 ABCSAMPLEDEFANOTHERSAMPLE 999999999999999999999993
P0666 1109011644 ABCSAMPLEDEFANOTHERSAMPLE IIIIIIIIIIIIIIIIIIIIII93
0666 G TENT S ABCSAMPLEDEFANOTHERSAMPLE UUUUUUUUUUUUUUUUUUUUUU43
P0666 1109011644TFABCSAMPLEDEFANOTHERSAMPLE PPPPPPPPPPPPPPPPPPPPPP92