#!/usr/bin/perl # # Grep for something and display the line and # the N lines following the match (default 1) # Prefix each line with the filename # if there is more than 1 file argument # Exit status: # 0 - a match was found # 1 - No match was found # >1 - An error was encountered (even if a match was found) use Getopt::Std; $usage_str = < 1 and ! $opt_h) ? sub { "$ARGV: " } : sub { '' }; $SIG{__WARN__} = sub { warn $_[0]; $error = 2 }; $status = 1; $i=0; while (<>) { ($status, $i) = (0, $n) if ! ($opt_r and $i) and /$pttrn/; $i--, print &$filename, $_ if $i; $i = 0 if eof; } exit($error || $status);