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.

Full log


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.




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.