Rasgele girdi ile çalışan bir sed
çözüm ( -n
yani otomatik yazdırma olmadan):
sed -n '/SomeTestAA/!p # if line doesn't match, print it
: m # label m
//{ # if line matches
$!{ # and if it's not the last line
n # empty pattern space and read in the next line
b m # branch to label m (so n is repeated until a
} # line that's read in no longer matches) but
} # nothing is printed
' infile
yani bir girdi ile
SomeTestAAXX
SomeTestAAYY
+ one line
SomeTestONE
Message body
EndTest
########
SomeTestTWO
something here
EndTest
SomeTestAABC
+ another line
SomeTestTHREE
EndTest
SomeTestAA
+ yet another line
çalışan
sed -n -e '/SomeTestAA/!p;: m' -e '//{' -e '$!{' -e 'n;b m' -e '}' -e'}' infile
çıktılar
SomeTestONE
Message body
EndTest
########
SomeTestTWO
something here
EndTest
SomeTestTHREE
EndTest
yani, tam olarak grep -A1 SomeTestAA infile
seçecek çizgileri kaldırır :
SomeTestAAXX
SomeTestAAYY
+ one line
--
SomeTestAABC
+ another line
--
SomeTestAA
+ yet another line