emacs-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[debbugs-tracker] bug#20864: closed (How to preserve newlines in sed tex


From: GNU bug Tracking System
Subject: [debbugs-tracker] bug#20864: closed (How to preserve newlines in sed text replacement command?)
Date: Wed, 25 Jan 2017 02:10:01 +0000

Your message dated Wed, 25 Jan 2017 02:09:12 +0000
with message-id <address@hidden>
and subject line Re: How to preserve newlines in sed text replacement command?
has caused the debbugs.gnu.org bug report #20864,
regarding How to preserve newlines in sed text replacement command?
to be marked as done.

(If you believe you have received this mail in error, please contact
address@hidden)


-- 
20864: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=20864
GNU Bug Tracking System
Contact address@hidden with problems
--- Begin Message --- Subject: How to preserve newlines in sed text replacement command? Date: Sun, 21 Jun 2015 15:15:24 +0200 User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0
Hello,

Are you interested to clarify escaping of new-line characters
a bit more?
http://sed.sourceforge.net/sedfaq4.html#s4.1

I would appreciate your advices for the following results
which I observe for the software version 4.2.2-7.1
on my openSUSE system.

address@hidden:~> cat test_template2.txt
*************
# placeholder
=============

address@hidden:~> XY=$(<two_lines.txt) && echo ">$XY<"
>  one
| two<
address@hidden:~> sed "s%# placeholder%${XY//$'\n'/$'\\\\n'}%g" 
test_template2.txt
*************
  one\n| two
=============

address@hidden:~> LANG=C sed "s%# placeholder%${XY//$'\n'/$'\\\\\n'}%g" 
test_template2.txt
sed: -e expression #1, char 23: unterminated `s' command
address@hidden:~> sed "s%# placeholder%${XY//$'\n'/$'\\\\\\n'}%g" 
test_template2.txt
*************
  one\
| two
=============


Which number of backslashes should be appropriate
for the desired pattern substitution in a shell variable?

Regards,
Markus



--- End Message ---
--- Begin Message --- Subject: Re: How to preserve newlines in sed text replacement command? Date: Wed, 25 Jan 2017 02:09:12 +0000 User-agent: Mutt/1.5.23 (2014-03-12)
tag 20864 notabug
stop

Hello,

Sorry for the delayed response.

Are you interested to clarify escaping of new-line characters
a bit more?
http://sed.sourceforge.net/sedfaq4.html#s4.1

This sed FAQ page is not maintained by us (GNU sed developers),
and we can not change it.

Which number of backslashes should be appropriate
for the desired pattern substitution in a shell variable?

I think there is some delicate interplay between the shell
and sed in the examples you provided (for one, not all shells
support the $'\n' syntax).

It might be better to separate the steps and see which cause problems.

As for sed, A single backslash is what's needed to indicate
a newline character:

   $ echo xyz | sed 's/y/\n/' | od -c
   0000000   x  \n   z  \n

I'm marking this as 'done', but discussion can continue
by replying to this thread.

regards,
- assaf


--- End Message ---

reply via email to

[Prev in Thread] Current Thread [Next in Thread]