Print line, which is situated 2 lines before the match(pattern).
I tried next:
sed -n \': loop
/.*/h
:x
{n;n;/cen/p;}
s/./c/p
t x
s/n/c/p
t loop
{g;p
The script:
sed -n "1N;2N;/XXX[^\n]*$/P;N;D"
works as follows:
1N;2N
XXX
anywhere in the last line, and if found print the first line of the pattern space, P
N
D
, noting that 1N;2N
is no longer applicable