Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

egrep with multiple conditions.

6 views
Skip to first unread message

Hongyi Zhao

unread,
Apr 2, 2015, 7:30:41 PM4/2/15
to
Hi all,

See the following example:

egrep 'a|b' file

and

egrep '(a|b)' file

I run some tests for the above two methods, it seems that all of these
tests will give the same results.

So, are the above two methods exactly same for all case?

Regards
--
.: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.

Barry Margolin

unread,
Apr 2, 2015, 7:38:49 PM4/2/15
to
In article <mfkjet$jet$1...@aspen.stu.neva.ru>,
Hongyi Zhao <hongy...@gmail.com> wrote:

> Hi all,
>
> See the following example:
>
> egrep 'a|b' file
>
> and
>
> egrep '(a|b)' file
>
> I run some tests for the above two methods, it seems that all of these
> tests will give the same results.
>
> So, are the above two methods exactly same for all case?

Yes.

Parentheses are needed around alternatives when it's not the entire
regexp, e.g.

egrep 'foo(a|b)' file

egrep '^(a|b)$' file

But parentheses around an entire regexp are redundant.

--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

Hongyi Zhao

unread,
Apr 2, 2015, 8:01:38 PM4/2/15
to
On Thu, 02 Apr 2015 19:38:44 -0400, Barry Margolin wrote:

> Parentheses are needed around alternatives when it's not the entire
> regexp, e.g.
>
> egrep 'foo(a|b)' file
>
> egrep '^(a|b)$' file
>
> But parentheses around an entire regexp are redundant.
>
> bar...@alum.mit.edu

Thanks for your notes.
0 new messages