In the awk
below I am trying to remove all lines above and including the pattern Test
or Test2
. Each block is seperated by a newline and Test2
also appears in the lines to keep but it will always have additional text after it. The Test
to remove will not. The awk
executed until the ||
was added but only removed the first instance of Test
, that is the first 3 lines including the line with Test
in it. Thank you :).
file
xxx-xxx 00-0002_Last,First-Id
xxx-xxx 00-0003_Las,Fir-Id
xxx-xxx 00-0004_La,Fi-Id
R_2019_03_00_00_00_00_xxxx_zz-000-000-Test
xxx-xxx 00-0006-yyyy
xxx-xxx 190326-yyyy
R_2019_03_00_00_00_00_xxxx_zz-000-zzz-v5.6_Test2_Additional_xxxx_xxx_xxx_xx_xxx
xxx-xxx Negative_Test
xxx-xxx Positive_Test
R_2019_03_00_00_00_00_xxxx_zz-000-000-v5.6_Test2
xxx-xxx 00-0000_L,F
xxx-xxx 00-0001_L2,F2
R_2019_03_00_00_00_00_xxxx_zz-000-000-Test
xxx-xxx xx-xxxx_Test,Test1
R_2019_03_00_00_00_00_xxxx_zz-000-000_Test2
xxx-xxx 00-0005-yyyy
R_2019_03_00_00_00_00_xxxx_zz-000-zzz-v5.6_Test2_Additional_xxxx_xxx_xxx_xx_xxx
desired
xxx-xxx 00-0006-yyyy
xxx-xxx 190326-yyyy
R_2019_03_00_00_00_00_xxxx_zz-000-zzz-v5.6_Additional_xxxx_xxx_xxx_xx_xxx
xxx-xxx 00-0005-yyyy
R_2019_03_00_00_00_00_xxxx_zz-000-zzz-v5.6_Additional_xxxx_xxx_xxx_xx_xxx
awk
awk -F '\n' '/Test || Test2/$ && getline, 0' file