LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-31-2009, 03:15 PM   #1
jax8
Member
 
Registered: Feb 2004
Location: Australia
Distribution: Ubuntu, Fedora 10
Posts: 632

Rep: Reputation: 31
Multiline sed quesion


SOLVED

You need a \ at the end of each line like this.

Code:
sedString='\
Many\
lines\
of \
code \
that \
go \
for\
a \
long\
time\
'
sed -i 's|that| a\'"$sedString"' |' /home/jack/myfile
-------------------------------------------------------------------


Say I have the following in my shell script:

Code:
sedString='
Many
lines
of 
code 
that 
go 
for
a 
long
time
'
sed -i 's|that| a\'"$sedString"' |' /home/jack/myfile
When I run this I get an error:
sed: -e expression #1, char 36: unterminated `s' command


How do I fix this?

Last edited by jax8; 04-01-2009 at 01:34 AM. Reason: SOLVED
 
Old 03-31-2009, 03:28 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
So, you want to replace the first occurrence of the word "that" with the contents of sedString (plus the spaces and the "a").

I'm not sure of all the nuances of this, but first try using just double-quotes--like so:

Code:
sed -i "s|that| a$sedString |" /home/jack/myfile
The next concern might be that it will fail if sedString contains the "|" character.
 
Old 03-31-2009, 03:42 PM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
I tried it with a "multi-line" string and it failed, but it works with a simple string---eg "sedString=foo"

I'm stumped for the moment......
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sed - multiline search/replace with wildcard troubles Yalla-One Programming 4 12-29-2008 12:01 PM
vim or sed multiline regexp matching eentonig Programming 1 09-08-2008 09:06 AM
sed and multiline delete aliyesami Programming 3 06-27-2008 02:03 PM
substituting multiline string in sed rohit2983 Programming 3 01-31-2007 09:00 AM
quick sed quesion DBabo Linux - Software 1 07-24-2005 01:11 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration