#!/usr/bin/perl # supergrep: search for simultaneous occurrence # of several patterns in many files # and report the matching filenames $version="1.00"; $date="10 Feb 2005"; # by Nick Manini sub print_help { print STDERR < file1 EOF return; } { while($p=shift(@ARGV)){ if($p=~/^[^\-]/){ push(@files,$p); next; } # [-e pattern] sets the patterns if($p eq "-e"){ push(@patterns,shift(@ARGV)); next; } if($p eq "-h"){ print_help; exit; } print_help; print STDERR "Invalid option $p!\n "; exit; } foreach $file (@files){ $#flag=-1; foreach $pattern (@patterns){ $flag{$pattern}=0; } open(INPUT,$file) || die "Could not open file $file\n"; while(){ foreach $pattern (@patterns){ if(/${pattern}/){ $flag{$pattern}=1; } } } close(INPUT); $prod=1; foreach $pattern (@patterns){ $prod*=$flag{$pattern}; } if($prod==1){ print "$file\n"; } } }