#!/usr/local/bin/perl
#Others might use /usr/bin/perl
# Gives neighborhood of a grep command.
#Results to standard out.

$numargs = @ARGV;
open(IN, $ARGV[1]);
if ($numargs != 2) {die "Usage: ngrep pattern file\n";}
$prev1 = "";
$prev2 = "";
$prev3 = "";
while (<IN>) {
   if (/$ARGV[0]/) { print "$prev1$prev2$prev3-->$_\n";}
   $prev1 = $prev2;
   $prev2 = $prev3;
   $prev3 = $_;
}
