How can find a specific number in a text block and print the complete text block beginning with the key word \"BEGIN\"
and ending with \"
A bit lenghty but the RS-trick was already posted :-)
BEGIN {found=0;start=0;i=0}
/BEGIN/ {
start=1
delete a
}
/.*567.*/ {found=1}
{
if (start==1) {
a[i++]=$0
}
}
/END/ {
if (found) {
for (i in a)
print a[i]
}
found=0
start=0
delete a
}
Output:
$ awk -f s.awk input
BEGIN
A: xyz
B: 56789
C: abc
END
BEGIN
A: ghi
B: 56712
C: pqr
END