Sed substitution bugs
Tim Robbins
tjr at FreeBSD.ORG
Tue Jun 3 18:35:39 PDT 2003
On Tue, Jun 03, 2003 at 03:42:25PM +0100, Tony Finch wrote:
> $ echo foo | sed 's/ */,/g'
> ,f,o,o
> $
>
> On Solaris and Linux I get ,f,o,o, (which is what I expected).
It looks like I may have introduced this bug when I made the semi-dramatic
change of making 'sed' not store newlines in the line buffers -- OpenBSD's sed
gives the right result. I agree that the current output is wrong and that
it should be ",f,o,o,".
FWIW, 7th Edition sed gets into an infinite loop on that input.
> The following work correctly:
>
> $ echo | sed 's/ */,/g'
> ,
> $ echo foo | sed 's/ *$/,/g'
> foo,
> $
>
> Here's another (related) bug:
I can't claim responsibility for this one :-) But I agree that it looks like a
bug.
>
> $ echo foo | sed 's/ */,/1'
> ,foo
> $ echo foo | sed 's/ */,/2'
> ,foo
> $ echo foo | sed 's/ */,/3'
> ,foo
> $ echo foo | sed 's/ */,/4'
> ,foo
> $ echo foo | sed 's/ */,/5'
> ,foo
> $
The patch looks fine, but it isn't obvious to me that the second part
(handling the /nnn bits) is correct. It seems to produce the right output
though.
Tim
More information about the freebsd-standards
mailing list