in reply to Re: grep for lines containg two variables
in thread grep for lines containg two variables

Just a couple of queries...

What if one string is contained in the other but should not be counted?
Ok so add white space checks/breaks to the search strings.

Do you need to lookahead on both strings? This seems to work.
@interesting_lines = grep /(?=.*$string1).*$string2/,@log;

Replies are listed 'Best First'.
Re^3: grep for lines containg two variables
by ikegami (Patriarch) on Dec 08, 2005 at 15:07 UTC
    What if one string is contained in the other but should not be counted?

    That's tricky. Do you really want that? I don't have the time right now to spend the effort on a what-if you won't use.

    Do you need to lookahead on both strings?

    No, it's optional on the last one. If you had 4 strings, you'd need the lookahead on the first three, but it would be optional on the fourth.

      Nah I don't want any of it, just commenting.

      If you are looking for whole words then you could use spaces around your searches but else it would be a real pain I'd agree.
Re^3: grep for lines containg two variables
by ikegami (Patriarch) on Dec 08, 2005 at 18:16 UTC
    What if one string is contained in the other but should not be counted?

    How about

    grep /$string1.*$string2|$string2.*$string1/,