[Toybox] sed N at EOF

enh enh at google.com
Mon Sep 12 08:33:16 PDT 2022


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

*~$ *

On Mon, Sep 12, 2022 at 6:23 AM Rob Landley <rob at landley.net> wrote:

> Posix says the N command does NOT trigger the default print at EOF:
>
> https://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html
>
> [2addr]N
>
>   Append the next line of input, less its terminating <newline>, to the
> pattern
>   space, using an embedded <newline> to separate the appended material
> from the
>   original material. Note that the current line number changes.
>
>   If no next line of input is available, the N command verb shall branch
> to the
>   end of the script and quit without starting a new cycle or copying the
> pattern
>   space to standard output.
>
> Except that's not what the gnu/dammit version does:
>
>   $ echo one | sed N
>   one
>   $ echo -e 'one\none\none' | sed 'N;ax'
>   one
>   one
>   x
>   one
>
> Why? (It looks like N acts as "b" at eof, which will do the default print
> as
> normal at end of pattern, but that's not what posix SAID to do...? I
> implemented
> what posix sed. At the time, I thought that was what the gnu/dammit one was
> doing too, but apparently not in devuan baywatch?)
>
> Rob
> _______________________________________________
> Toybox mailing list
> Toybox at lists.landley.net
> http://lists.landley.net/listinfo.cgi/toybox-landley.net
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20220912/75723218/attachment.htm>


More information about the Toybox mailing list