You should be able to do it in one iteration...
I would use a queue to store the context lines
Start by inspecting each line.
So, basically, the queue saves up a maximum of $maxPreContext lines of context from before the duplication, and you keep printing $maxPostContext lines for context after the duplication. If another duplicate appears quickly, you don't get multiple copies of the same context because the queue has not refilled.
In reply to Re: Padding search results with context
by SuicideJunkie
in thread Padding search results with context
by moritz
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |