[Toybox] sed N at EOF

Rob Landley rob at landley.net
Mon Sep 12 12:32:41 PDT 2022


On 9/12/22 10:33, enh wrote:
> here's BSD sed on macOS:
> 
> *~$ *echo one | /usr/bin/sed N
> 
> *~$ *echo -e 'one\none\none' | /usr/bin/sed 'N;ax'
> 
> sed: 1: "N;ax": command a expects \ followed by text
> 
> *~$ *

Yeah, being able to have the payload of "a" or "i" on the same line is a gnu
extension, probably needs something like sed $'n;a\nx' or even
sed -e 'N;a' -e 'x'

Either way, looks like mac sed is following posix. (Unsurprising given it seems
to be a pure-ish posix implementation.)

What I'm wondering was "did the gnu behavior change since I implemented sed, or
did I just read the spec and not test gnu in this corner case"? Hmmm... I have a
xubuntu 12.10 iso image lying around, boot that, and...

  $ echo one | sed N
  one

Yup, looks like I implemented what posix said rather than what gnu did. (The
next question of course is gnu does gnu KNOW they're deviating from posix here?
Is this intentional, or a bug?)

Eh, fix it up while I'm in the area. If gnu's behavior has been consistent for
ten years, _matching_ it probably isn't going to cause cause problems?

Rob

P.S. Ok, now I'm curious HOW long it's been... In Red hat 9 from 2003 the "N"
after EOF adds a blank line. So it ends with two \n. Bravo.


More information about the Toybox mailing list