On Sun, Sep 05, 2021 at 02:01:37PM +0200, Ingo Schwarze wrote: > Hello, > > i see where Ian's confusion is coming from, even though arguably, > the existing text is accurate. But it is not a good idea to insert > exceptions as parenthetic remarks in the middle of an enumeration > of steps that is already somewhat long and complicated. > > I think it is better to explain the special rules for D processing > in the paragraph describing D (surprise, surprise) rather than in > the middle of the general description of what a "cycle" is. > > > Consider the following minimal example: > > $ printf 'axb' | sed -n 'y/x/\n/;s/^b/c/;P;D' > a > c > > The D deletes "a\n" from the pattern space. > After that, the next cycle is entered with "b" in the pattern space, > without copying a new line into the pattern space. > > > OK? > Ingo > > > Index: sed.1 > =================================================================== > RCS file: /cvs/src/usr.bin/sed/sed.1,v > retrieving revision 1.48 > diff -u -r1.48 sed.1 > --- sed.1 17 Mar 2016 05:27:10 -0000 1.48 > +++ sed.1 5 Sep 2021 11:46:48 -0000 > @@ -140,9 +140,6 @@ > cyclically copies a line of input, not including its terminating newline > character, into a > .Em pattern space , > -(unless there is something left after a > -.Ic D > -function), > applies all of the commands with addresses that select that pattern space, > copies the pattern space to the standard output, appending a newline, and > deletes the pattern space. > @@ -331,7 +328,8 @@ > Delete the pattern space and start the next cycle. > .It [2addr] Ns Ic D > Delete the initial segment of the pattern space through the first > -newline character and start the next cycle. > +newline character and start the next cycle without copying the next > +line of input into the pattern space. > .It [2addr] Ns Ic g > Replace the contents of the pattern space with the contents of the > hold space.
This is an improvement. This should be compared to the POSIX text: If the pattern space contains no <newline>, delete the pattern space and start a normal new cycle as if the d command was issued. Otherwise, delete the initial segment of the pattern space through the first <newline>, and start the next cycle with the resultant pattern space and without reading any new input. The difference is that the POSIX text explicitly says that "D" should act like "d" if there is no newline character in the pattern space. The OpenBSD text does not actually say what happens if there is no newline character in the pattern space (I believe that OpenBSD sed behaves as POSIX describes). -- Andreas (Kusalananda) Kähäri SciLifeLab, NBIS, ICM Uppsala University, Sweden .