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. Sed or awk solutions would be fine.
Edit: 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 StartPattern
For multiple StartPatterns with missing EndPattern, I'd only like lines from the last StartPattern to the EndPattern.
For a StartPattern which reaches the EOF without an EndPattern, I'd like everything up to the EOF, followed by inputting a string to warn that EOF was reached.