sed BSD/macOS Sed vs. GNU Sed vs. the POSIX Sed specification Append literal text to a line with function 'a'


Note: For brevity, the commands use here-strings (<<<) and ANSI C-quoted strings ($'...'). Both these shell features work in bash, ksh, and zsh.

 # GNU Sed
 $ sed '1 a appended text' <<<'line 1'
 line 1
 appended text

 # BSD Sed (multi-line form)
 sed '1 a\
 appended text' <<<'line 1'

 # BSD Sed (single-line form via a Bash/Ksh/Zsh ANSI C-quoted string)
 sed $'1 a\\\nappended text' <<<'line 1'

Note how BSD Seed requires a \ followed by an actual newline to pass the text to append.
The same applies to the related i (insert) and c (delete and insert) functions.