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

Re: sed bug

5 views
Skip to first unread message

Paolo Bonzini

unread,
Feb 14, 2013, 7:19:44 AM2/14/13
to Slawomir Kuszczynski, bug-gn...@gnu.org
Il 14/02/2013 10:12, Slawomir Kuszczynski ha scritto:
>
> Result of this simple sed:
> echo ABC1234_1.0 | sed -r 's/^[A-Z]*([0-9])/\1/'
> is:
> 1234_1.0
> but should be:
> 1
>
> This not happen in python2.7 and python3.2:
> $ python -c "import re; print(re.sub(r'^[a-zA-Z]*([0-9]).*',r'\1',
> 'ABC1234_1.0'))"
> 1

The regular expressions are different in the two cases. You removed the
.* in the sed version.

$ echo ABC1234_1.0 | sed -r 's/^[A-Z]*([0-9]).*/\1/'
1

Paolo

Slawomir Kuszczynski

unread,
Feb 14, 2013, 4:12:17 AM2/14/13
to bon...@gnu.org, bug-gn...@gnu.org
Hi,

I found bug in sed. It is related to reverse matching, see examples below:

Result of this simple sed:
echo ABC1234_1.0 | sed -r 's/^[A-Z]*([0-9])/\1/'
is:
1234_1.0
but should be:
1

This not happen in python2.7 and python3.2:
$ python -c "import re; print(re.sub(r'^[a-zA-Z]*([0-9]).*',r'\1',
'ABC1234_1.0'))"
1


Environment details:

$ sed --version
GNU sed version 4.2.1
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,
to the extent permitted by law.

GNU sed home page: <http://www.gnu.org/software/sed/>.
General help using GNU software: <http://www.gnu.org/gethelp/>.
E-mail bug reports to: <bug-gn...@gnu.org>.
Be sure to include the word ``sed'' somewhere in the ``Subject:'' field.

$ uname -a
Linux jaaa 3.0.0-30-generic #47-Ubuntu SMP Wed Jan 2 23:16:29 UTC 2013
x86_64 x86_64 x86_64 GNU/Linux


--
BR,
Slawomir Kuszczynski

Davide Brini

unread,
Feb 15, 2013, 4:19:02 AM2/15/13
to Slawomir Kuszczynski, bon...@gnu.org, bug-gn...@gnu.org
On Thu, 14 Feb 2013 10:12:17 +0100, Slawomir Kuszczynski
<slawomir.k...@gmail.com> wrote:

> Hi,
>
> I found bug in sed. It is related to reverse matching, see examples below:
>
> Result of this simple sed:
> echo ABC1234_1.0 | sed -r 's/^[A-Z]*([0-9])/\1/'
> is:
> 1234_1.0
> but should be:
> 1

No, it should not. Think what should be the result of

echo abc | sed -r 's/(c)/\1/'

--
D.

Slawomir Kuszczynski

unread,
Feb 15, 2013, 5:13:02 AM2/15/13
to Davide Brini, bon...@gnu.org, bug-gn...@gnu.org
Hi,

Thanks for help

You are right.
It was my fault, sorry for trouble.



2013/2/15 Davide Brini <dav...@gmx.com>
--
BR,
Slawomir Kuszczynski
0 new messages