[ad_1]
If you can slurp whole input:
perl -e'undef$/;
$a=<>;
print "$_\n" for $a=~m/(?:\b\S+\b\s+){5}your regexp(?:\s+\b\S+\b){5}/sg
' <input
— 5 words of context.
[ad_2]
solved how to print n words of context while searching text [closed]