GNU bug report logs - #22943
sed: + intepreted twice

Previous Next

Package: sed;

Reported by: "Dam, Jesse van" <jesse.vandam <at> wur.nl>

Date: Tue, 8 Mar 2016 16:33:02 UTC

Severity: normal

Tags: notabug

Done: Assaf Gordon <assafgordon <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 22943 in the body.
You can then email your comments to 22943 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-sed <at> gnu.org:
bug#22943; Package sed. (Tue, 08 Mar 2016 16:33:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to "Dam, Jesse van" <jesse.vandam <at> wur.nl>:
New bug report received and forwarded. Copy sent to bug-sed <at> gnu.org. (Tue, 08 Mar 2016 16:33:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: "Dam, Jesse van" <jesse.vandam <at> wur.nl>
To: "bug-sed <at> gnu.org" <bug-sed <at> gnu.org>
Subject: sed: + intepreted twice
Date: Tue, 8 Mar 2016 12:06:43 +0000
Hi,


The plus sign in the following sed command is interpreted twice. One time for '1 or more occurrences' and one time as match a plus sign. I think this is incorrect behavior. Correct me if I am wrong.


echo '+710+1869' | sed 's/\(.[0-9]+\).*/\1/g'

Results in

+710+

Expected result

+710


Version: sed (GNU sed) 4.2.2


Thanks,

Jesse van dam







Information forwarded to bug-sed <at> gnu.org:
bug#22943; Package sed. (Tue, 08 Mar 2016 16:40:02 GMT) Full text and rfc822 format available.

Message #8 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Davide Brini <dave_br <at> gmx.com>
To: bug-sed <at> gnu.org
Subject: Re: bug#22943: sed: + intepreted twice
Date: Tue, 8 Mar 2016 17:39:36 +0100
On Tue, 8 Mar 2016 12:06:43 +0000, "Dam, Jesse van" <jesse.vandam <at> wur.nl>
wrote:

> Hi,
> 
> 
> The plus sign in the following sed command is interpreted twice. One time
> for '1 or more occurrences' and one time as match a plus sign. I think
> this is incorrect behavior. Correct me if I am wrong.
> 
> 
> echo '+710+1869' | sed 's/\(.[0-9]+\).*/\1/g'
> 
> Results in
> 
> +710+
> 
> Expected result
> 
> +710

By default sed uses basic regular expressions (BRE), where "+" is not a
special character, so in your example it's matched literally and you're
getting the expected result.

To do what you wanted you need extended REs (ERE), as in

$ echo '+710+1869' | sed -r 's/(.[0-9]+).*/\1/g'
+710

or you need to tell sed to enable "+" as a nonstandard BRE metacharacter by
escaping it:

$ echo '+710+1869' | sed 's/\(.[0-9]\+\).*/\1/g'
+710

HTH

-- 
D.




Information forwarded to bug-sed <at> gnu.org:
bug#22943; Package sed. (Tue, 08 Mar 2016 17:41:01 GMT) Full text and rfc822 format available.

Message #11 received at 22943 <at> debbugs.gnu.org (full text, mbox):

From: Jim Meyering <jim <at> meyering.net>
To: Davide Brini <dave_br <at> gmx.com>
Cc: 22943 <at> debbugs.gnu.org
Subject: Re: bug#22943: sed: + intepreted twice
Date: Tue, 8 Mar 2016 09:40:08 -0800
tags 22943 notabug
close 22943
thanks

On Tue, Mar 8, 2016 at 8:39 AM, Davide Brini <dave_br <at> gmx.com> wrote:
> On Tue, 8 Mar 2016 12:06:43 +0000, "Dam, Jesse van" <jesse.vandam <at> wur.nl>
> wrote:
...
> By default sed uses basic regular expressions (BRE), where "+" is not a
> special character, so in your example it's matched literally and you're
> getting the expected result.
>
> To do what you wanted you need extended REs (ERE), as in
>
> $ echo '+710+1869' | sed -r 's/(.[0-9]+).*/\1/g'
> +710
>
> or you need to tell sed to enable "+" as a nonstandard BRE metacharacter by
> escaping it:
>
> $ echo '+710+1869' | sed 's/\(.[0-9]\+\).*/\1/g'
> +710

Thank you for helping triage, Davide.
Since this is not a bug, I'm marking it as "notabug"
in the issue tracker with a comment above. Also closing it.




Added tag(s) notabug. Request was from Assaf Gordon <assafgordon <at> gmail.com> to control <at> debbugs.gnu.org. (Tue, 24 Jan 2017 23:33:02 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 22943 <at> debbugs.gnu.org and "Dam, Jesse van" <jesse.vandam <at> wur.nl> Request was from Assaf Gordon <assafgordon <at> gmail.com> to control <at> debbugs.gnu.org. (Tue, 24 Jan 2017 23:33:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 22 Feb 2017 12:24:06 GMT) Full text and rfc822 format available.

This bug report was last modified 8 years and 176 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.