[Toybox] sed s/pattern/\<newline>/

Felix Janda felix.janda at posteo.de
Fri Jan 9 00:13:46 PST 2015


Rob Landley wrote:
> On 01/08/2015 03:38 PM, Felix Janda wrote:
> > sed doesn't allow embedded newlines in the replacement for s///, e.g.
> > 
> > s/walrus/wal\
> > rus/
> 
> Indeed, that's the next sed bug I'm wrestling with right now.
> 
> > It is not obvious to me how to fix this. There is some code for dealing
> > with line continuations but I don't see how to use it.
> 
> I've blogged about this but haven't swapped my blog to the new year yet.
> Lemme go do that...
> 
> http://landley.net/notes-2015.html#04-01-2015

Thanks.

As to "why would anyone do that? That's supported?", POSIX says that
"A line can be split by substituting a <newline> into it.". On the other
hand, '\n' in the replacement text is not specified by POSIX. So scripts
trying to be portable use escaped newlines for splitting lines with sed.
(I hit the bug when trying to build musl.)

> P.S. I hit a bug after that one too, but don't remember what it was at
> the moment. I promoted sed too early. Fixing it before the next release...

Thanks,
Felix

 1420791226.0


More information about the Toybox mailing list