Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #226376

Re: POSIX compliant sed making newline character

From Greg Wooledge <wooledg@eeg.ccf.org>
Newsgroups linux.debian.user
Subject Re: POSIX compliant sed making newline character
Date 2020-08-21 20:40 +0200
Message-ID <AGk7f-805-3@gated-at.bofh.it> (permalink)
References <AGjkR-7v0-1@gated-at.bofh.it> <AGjuy-7ye-9@gated-at.bofh.it> <AGjEd-7QM-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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.

Back to linux.debian.user | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

POSIX compliant sed making newline character john doe <johndoe65534@mail.com> - 2020-08-21 19:50 +0200
  Re: POSIX compliant sed making newline character Greg Wooledge <wooledg@eeg.ccf.org> - 2020-08-21 20:00 +0200
    Re: POSIX compliant sed making newline character john doe <johndoe65534@mail.com> - 2020-08-21 20:10 +0200
      Re: POSIX compliant sed making newline character Greg Wooledge <wooledg@eeg.ccf.org> - 2020-08-21 20:40 +0200
        Re: POSIX compliant sed making newline character Greg Wooledge <wooledg@eeg.ccf.org> - 2020-08-21 20:40 +0200
          Re: POSIX compliant sed making newline character john doe <johndoe65534@mail.com> - 2020-08-21 21:00 +0200
            Re: POSIX compliant sed making newline character john doe <johndoe65534@mail.com> - 2020-08-21 21:10 +0200
              Re: POSIX compliant sed making newline character Andrei POPESCU <andreimpopescu@gmail.com> - 2020-08-22 18:40 +0200
                Re: POSIX compliant sed making newline character john doe <johndoe65534@mail.com> - 2020-08-22 20:50 +0200
            Re: POSIX compliant sed making newline character Greg Wooledge <wooledg@eeg.ccf.org> - 2020-08-21 21:10 +0200

csiph-web