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 "END"
? Basically this is what my file looks like:
BEGIN
A: abc
B: 12345
C: def
END
BEGIN
A: xyz
B: 56789
C: abc
END
BEGIN
A: ghi
B: 56712
C: pqr
END
[...]
If I was looking for '^B: 567'
, I would like to get this output:
BEGIN
A: xyz
B: 56789
C: abc
END
BEGIN
A: ghi
B: 56712
C: pqr
END
I could use grep here (grep -E -B2 -A2 "^B: 567" file
), but I would like to get a more general solution. I guess awk or sed might be able to do this!?
Thanks! :)