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


Groups > comp.programming > #4121

Escaping of line breaks for text replacement

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsfeed.fsmpi.rwth-aachen.de!news-1.dfn.de!news.dfn.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Markus Elfring <Markus.Elfring@web.de>
Newsgroups comp.unix.programmer, comp.programming
Subject Escaping of line breaks for text replacement
Date Sun, 02 Mar 2014 14:00:52 +0100
Lines 38
Message-ID <bngoc5F196mU1@mid.individual.net> (permalink)
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-15
Content-Transfer-Encoding 7bit
X-Trace individual.net n5TzeptclREduH9RMVATeQ8Gdyix0NME+vcClfmtnNz+mEjZSV
Cancel-Lock sha1:kovFuoBf8OPl51u0xuioBAweuCo=
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0
Xref csiph.com comp.unix.programmer:5148 comp.programming:4121

Cross-posted to 2 groups.

Show key headers only | View raw


Hello,

I get the following result if I try out such a command on my openSUSE system.

elfring@Sonne:~> $SHELL --version && sed --version && LINE='echo ---' && $LINE \
&& DRAFT='template1.txt' && cat $DRAFT && $LINE \
&& INPUT='replacement1.txt' && cat $INPUT && XY=$(< $INPUT) && $LINE \
&& LANG=C sed "s/# placeholder/$XY/" $DRAFT
GNU bash, Version 4.2.45(1)-release (x86_64-suse-linux-gnu)
   ...
sed (GNU sed) 4.2.2
   ...
---
+++++++++++++
# placeholder
*************
---
ABC
XYZ
---
sed: -e expression #1, char 19: unterminated `s' command


I guess that the shown error message is an indication that I should add a bit of
escaping to the content of the variable "XY" which I inserted previously. I have
tried to achieve this with shell pattern substitution.

elfring@Sonne:~> XY=$(< $INPUT) && XY=${XY//\\\n/./} && echo $XY
ABC XYZ


I wonder why I do not get this approach to work so far with some additional
backslashes here. How should newlines be escaped for this purpose?

Would you like to share any further ideas?

Regards,
Markus

Back to comp.programming | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Escaping of line breaks for text replacement Markus Elfring <Markus.Elfring@web.de> - 2014-03-02 14:00 +0100
  Re: Escaping of line breaks for text replacement jt@toerring.de (Jens Thoms Toerring) - 2014-03-02 15:49 +0000
  Re: Escaping of line breaks for text replacement dave.gma+news002@googlemail.com.invalid (Dave Sines) - 2014-03-02 16:52 +0000
  Re: Escaping of line breaks for text replacement Kaz Kylheku <kaz@kylheku.com> - 2014-03-02 18:11 +0000
  Re: Escaping of line breaks for text replacement Siri Cruz <chine.bleu@yahoo.com> - 2014-03-07 02:47 -0800

csiph-web