bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: regexp bug in sed/grep?


From: Bob Proulx
Subject: Re: regexp bug in sed/grep?
Date: Sun, 29 Sep 2002 21:25:43 -0600
User-agent: Mutt/1.4i

Miles Bader <address@hidden> [2002-09-30 11:26:08 +0900]:
> In the following command, I think the `ABx' suffix should be deleted by
> the sed program, but it isn't:
> 
>    $ echo pqrABx | sed -e 's/AB*x?$//'
>    pqrABx

Sed implements basic regular expressions only.  The '?' is part of the
extended RE syntax.  Unfortunately the man page and info page only say
that this section needs to be documented exactly what it supports and
what it does not.

> grep fails similarly:
> 
>    $ echo pqrABx | grep 'AB*x?$'
>    <no output>

Again, grep implements basic regular expressions and not extended
REs.  if you want extended REs then you need to call grep as 'egrep'
which is the old method or call it 'grep -E' to get extended regular
expressions.

  echo pqrABx | grep -E 'AB*x?$'

> If I try the equivalent AWK program, it works as I expect:
> 
>    $ echo pqrABx | nawk '{ sub (/AB*x?$/, ""); print }'
>    pqr

Awk does implement extended regular expressions.  In the grand scheme
of things awk is a much newer program than either sed or grep and so
started out using the extended REs right at the start.

> Is this a bug with the regexp implementation in sed/grep, or am I just
> confused?

There is also a third class of regular expressions.  Those are the
type that the shell uses to expand file globs.  Those are '*.c' where
the '*' matches similarly to '.*' of the higher powered REs.

HTH
Bob




reply via email to

[Prev in Thread] Current Thread [Next in Thread]