in reply to Find certain words in multiple files
if you don't want to do much programming: , you could try the following:
#!/usr/bin/perl -w # literally, ALL this will do is show you whether the # string you're searching for is in both files. # you might want to know line numbers, too, but this won't # do it without modification. use strict; # get variable, and filenames from wherever ... if (in_file($pattern, $filename1) && in_file($pattern, $filename2) ) { print "Found $pattern in both $filename1 and $filename2\n"; } else { print "$pattern not found in both $filename1 and $filename2.\n"; } sub in_file { my ($pattern, $filename) = @_; open FILE, $filename or die "Can't open $filename: $!\n"; my $found =0; while (<FILE>) { # set found to a true value and exit the loop # if we find the pattern in the current line. $found=1, last if /$pattern/; } close FILE; $found; }
Of course, if you're on a *nix system, if (`/usr/bin/grep $pattern $filename1` && `/usr/bin/print grep $pattern $filename2`) {} could replace that whole sub, but then you have to worry about users putting in dumb patterns.
Philosophy can be made out of anything. Or less -- Jerry A. Fodor
|
|---|