in reply to Print a previous to previous of a matching line
This is not an uncommon task. Here is one possible solution which you can alter to suit your particular requirements.