bug-sed
[Top][All Lists]
Advanced

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

bug#23415: sed bug with the D command verb


From: Davide Brini
Subject: bug#23415: sed bug with the D command verb
Date: Sun, 1 May 2016 22:20:57 +0200

On Sun, 1 May 2016 19:58:28 +1200, Dylan Wagstaff <address@hidden>
wrote:

> *Documentation extract:*
> $ man sed
> [...]
> d - Delete pattern space. Start next cycle.
> 
> D - If pattern space contains no newline, start a normal new cycle as if
> the d command was issued. Otherwise, delete text in the pattern space up
> to the first newline, and restart cycle with the resultant pattern space,
> without reading a new line of input.
> [...]
> 
> which concurs with at least the 2013 edition of the specification found at
> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html#tag_20_116_13_03
> 
> *Issue:*
> The 'D' command verb always acts as the 'd' command verb (even with the
> presence of a newline in the pattern space).
> 
> *Steps to reproduce:*
> Using GNU bash
> 
> $ sed -e 's/newline/\n/; D; i\text from the i command' <<< "here-string
> with a newline in the middle of it"
> 
> *Expected output:*
> text from the i command
>  in the middle of it
> 
> *Actual output:*
> 
> (none)

I see no bug. The D command starts a new cycle, but nowhere you tell sed to
actually print the pattern space, nor you give it a chance to do
autoprinting at the end (due to the D command). For the same reason, the
"i" command is never executed. So the output is nothing as you see.

Let's step through the execution:

First cycle: input line is "here-string", so pattern space is
"here-string". The "s/newline/\n/" command does nothing, so pattern space
unchanged. "D" deletes it and leaves it empty (without printing anything),
since there's no newline in it, so sed reads in the next line of input. "i"
is not executed.

Second cycle: input line is "with a newline in the middle of it", so
pattern space is "with a newline in the middle of it", "s/newline/\n/"
replaces "newline" with an actual newline character, so the pattern space
is now "with a \n in the middle of it". "D" deletes up to the newline, the
pattern space becomes " in the middle of it". But D also starts a new cycle
(note that we still aren't printing anything) with the remaining pattern
space.

Third cycle: no input since we have data left in the pattern space, which
is " in the middle of it". Now the s/// command does nothing, and the
subsequet "D" deletes the pattern space (again, we're not printing
anything) and starts a new cycle.

Since now the pattern space is empty, sed should read in the next input
line, but there's no more input so sed terminates.

tl;dr: there is no bug.

-- 
D.





reply via email to

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