Bug 241206 - sed "a" command issued on the command-line doesn't append a newline
Summary: sed "a" command issued on the command-line doesn't append a newline
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 12.0-RELEASE
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-10-12 03:04 UTC by Tim Chase
Modified: 2019-10-12 03:04 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tim Chase 2019-10-12 03:04:20 UTC
To reproduce:

    $ jot 2 | sed '/1/a\
    > one point five'

Expected results (for comparison, gsed produces this output):

    1
    one point five
    2

Actual results

    1
    one point five2

If the command is put in a script, it works as expected (though there's also a newline as the last character of the script)

    $ cat example.sed
    a\
    one point five
    $ jot 2 | sed -f example.sed
    1
    one point five
    2

Attempts to manually add a newline

    $ sed '/1/a\
    > one point five\
    > ' input

work for BSD `sed` but then end up adding an extra newline if the same command is issued on a Linux box where sed==gsed.

The same also holds for the "c" and "i" commands.

As I understand it, the solution would involve noticing that an a/c/i command originates on the command-line and tacking on the extra newline at the end of the provided data.

(side note: tested in OpenBSD too and got the same results as FreeBSD)