in reply to How to print a matching line and one line above it?
Here’s the basic strategy...
Initialize a variable (or as the case may be, an array) to catch the last (the last n...) line(s) that have been seen. When you realize that you are now looking at a matching line, the variable (or array) contains the last line(s) that you saw before that one.
If the variable is undef (see the function, “defined()”), or if the array is empty, then there were no lines prior to the matching line.