I have a log file which reports on the output of a process, I'd like to extract all lines from between the last occurrence of two patterns.
The patterns will be along the lines of;
Summary process started at <datestring>
Summary process finished at <datestring> with return code <num>
There will be several instances of these patterns throughout the file, along with a lot of other information. I'd like to print the only the last occurrence.
I know that I can use:
sed -n '/StartPattern/,/EndPattern/p' FileName
to get lines between the patterns, but not sure how to get the last instance.
awk solutions would be fine.
I've not been clear at all about the behaviour that I want when multiple
StartPatterns appear with no
EndPattern, or if there's no
EndPattern before the end of file, after detecting a
- For multiple
StartPatterns with missing
EndPattern, I'd only like lines from the last
- For a
StartPatternwhich reaches the
EndPattern, I'd like everything up to the
EOF, followed by a warning that
EOFwas reached prematurely.