Re: grep AND regular expression

From: Vinod Gupta (vkgupta_at_princeton.edu)
Date: 11/07/03


Date: 7 Nov 2003 14:27:18 -0800

Barry Margolin <barry.margolin@level3.com> wrote in message news:<EKPqb.408$lK3.380@news.level3.com>...
> In article <17581f0c.0311070822.3b5fa7a1@posting.google.com>,
> Vinod Gupta <vkgupta@princeton.edu> wrote:
> >While one could search for str1 OR str2 by egrep "str1|str2",
> >what would be the regular expression to search for str1 AND str2?
>
> For very simple cases you can do:
>
> grep -E 'str1.*str2|str2.*str1'
>
> but this doesn't generalize very well because of combinatorial explosion
> (and it also fails completely if str1 and str2 overlap).

You are very right

>The more general way to solve it is with piping:
>
> grep 'str1' | grep 'str2' | grep 'str3' ...

Better, but this won't let us use full power of grep that we want to
apply
on records matching the ANDed expression, for instance, what if I want
to exclude the records matching the expression (-v)?

Vinod.



Relevant Pages

  • grep AND regular expression
    ... > but this doesn't generalize very well because of combinatorial explosion ... to apply on records matching the ANDed expression, for instance, ... Vinod. ...
    (comp.os.linux.misc)
  • Re: grep AND regular expression
    ... >> to apply on records matching the ANDed expression, for instance, ... Ha, ha...I see that you are a Perl fan, like me:) ... This is all the more reason to wonder why grep developers couldn't ...
    (comp.os.linux.misc)
  • Re: grep AND regular expression
    ... > to apply on records matching the ANDed expression, for instance, ... not (str1 and str2): ...
    (comp.os.linux.misc)