The sliding window concept is a generic way to solve such "n'th line before" , "x'th line after" requirements.
See Re^2: Grab 3 lines before and 2 after each regex hit (sliding window) and especially the code in the "update".
NB the window size in your example is just 2 then.
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
In reply to Re: Dealing with nextline of a file
by LanX
in thread Dealing with nextline of a file
by jnarayan81
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |