Re: POSIX compliant sed making newline character
On Fri, Aug 21, 2020 at 08:09:26PM +0200, john doe wrote:
> On 8/21/2020 7:51 PM, Greg Wooledge wrote:
> > If you're doing this from bash, you could use bash's special $'...'
> > quoting to pass a newline encoded as \n .
>
> So something like the following:
>
> $ sed '/line1/{N;N;a line-to-add$'\n'}' input-file
No. Use $'...' instead of '...'.
sed '/line1/{N;N;a line-to-add\n}' input-file
> > Otherwise, put an ACTUAL newline inside the quotes. You know, by
> > pressing the Enter key. That's portable to every sh family shell.
>
> Actually, I do not know, that is why I'm asking in here! :)
The Subject: header is a bit ambiguous, because you mention "POSIX
compliant sed", but you're asking on debian-user, where sed is not
necessarily POSIX compliant (GNU sed is notorious for having many
extensions).
Morever, it's not clear whether your operating environment is also
a POSIX *shell*.
Using a literal newline inside the single quotes is POSIX shell
compatible. $'...' is not.
Reply to: