bug-sed
[Top][All Lists]
Advanced

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

bug#19414: bug in sed


From: Davide Brini
Subject: bug#19414: bug in sed
Date: Sat, 20 Dec 2014 13:29:12 +0100

On Fri, 19 Dec 2014 15:56:52 -0600, "Buchs, Kevin J."
<address@hidden> wrote:

> I am using sed, version 4.2.1 on a few different systems. What I have 
> discovered is that inside a substitute command, a space alone is 
> magically anchored at the start of the line in an anti-greedy match.
> 
> As an example, consider this input stream:
> 
>   a                     <-- leading space
> b c
> d  e
> f    g
> 
> 
> Along with these one-liner invocations:
> 
> sed -e 's/ *//'
> sed -e 's/[ ]*//'
> sed -e 's/[[:space::]]*//'

These are equivalent for the sample input (assuming [[:space:]] is spelled
correctly)

> sed -e 's/ ?//'
> sed -e 's/ +//'

These two don't do what you think they do. You need -r for that.

 
> What seems to be happening is that the wildcard match gets anchored to 
> the beginning of the line with a zero character hit.
> 
> This case seems to apply not only to spaces but other characters.

I'm not sure what you would expect here. I see no bugs. If you ask for "zero
or more", you get "zero or more". In particular, you get "zero" if that's
what sed considers to be the best match at any given position (eg, at the
beginning of a line).
If you want "one or more", just say so:

sed -e 's/  *//'
sed -e 's/ \{1,\}//'
sed -re 's/ +//'

etc.


> 



-- 
D.





reply via email to

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