On Sun, 2 Jul 2000, Anthony E. Greene wrote:

> SoloCDM wrote:
> > 
> > While using grep, what is the best way to search for two subjects
> > within the same line instead of the following?
> > 
> > cat <filename> | grep <subject_one> | grep <subject_two>
> > 
> > This is not an "or" search with "-e", but an "and" search.
> 
> grep "^Subject:.*subject1.*subject2" filename

But he said they didn't necesarily need to be in the order subject1,
subject2 which this requires.

Here is a short perl script that does just this. You could make a few
minor mods to call it with the subjects as the arguments instead of them
being hard coded, but this is what you want.

#!/usr/bin/perl -wn

BEGIN {
    @terms = ('^Subject:', 'subject2', 'subject1');
}

my $match = 0;
foreach my $term (@terms) {
    next unless /$term/i;
    $match++;
}
print if $match == ($#terms + 1);


-- 
To unsubscribe: mail [EMAIL PROTECTED] with "unsubscribe"
as the Subject.

Reply via email to