sed print from last occurrence match until the end of file

Hi, i have file f1.txt with data like:
CHECK
a
b
CHECK
c
d
CHECK
e
f
JOB_START
....

I want to match the last occurrence of 'CHECK' until the end of the file.
I can use awk:

awk '/^CHECK/ { buf = "" } { buf = buf "\n" $0 } END { print buf }' f1.txt | tail +2

Is there a cleaner way of doing this used 'sed' command?
Our server is HP-UX 11.11 and 'tac' utility is not available, in case your solution suggests reversing the lines in the file first !

Thanks,
-srinivas yelamanchili

A translation into sed:

sed -n 'H; /^CHECK/h; ${g;p;}' f1.txt

Regards,
Alister

2 Likes

awk implicit buffering:

awk 'sub(".*\n"s,s)' s=CHECK RS= infile

*edit: This does not work if there are empty lines.
*edit2 it works if I use a null character.

awk 'sub(".*\n"s,s)' s=CHECK RS=\000 infile

@alister: nice and simple :b: