>From FreeBSD's grep man page (your grep may vary):
       -A NUM, --after-context=NUM
              Print  NUM lines of trailing context after matching
              lines.

       -B NUM, --before-context=NUM
              Print  NUM lines of leading context before matching
              lines.

If you are determined to do it in Perl, then slurp all of the
lines into an array and print @array[$i-N .. $i+M].

--kag

Reply via email to