Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 01-31-2007, 06:10 AM   #1
LQ Newbie
Registered: Dec 2006
Posts: 5

Rep: Reputation: 0
substituting multiline string in sed

Hi Experts

I am facing a problem while using sed to replace a multiline string

I have sed command stored in a file say command

command file has the following content


I want to replace
Number" string with "Contractnumtest"
the file with name say "file" which i have to edit is something like this


when i try to use sed to edit by doing this

sed -f commands $file > file_outptut1.txt

I am getting errors like
sed: command garbled: s/"Contract

I am using Solaris as OS.

Is it possible to replace the multiline string using sed or sed commands have to be end in one line???

any solution/suggestion/pointers to solve this problem are welcome

thanks in advance for helping
Old 01-31-2007, 06:59 AM   #2
Registered: Dec 2006
Location: Bracknell, UK
Distribution: SUSE 13.1
Posts: 159

Rep: Reputation: 33
You need to consult the sed&awk bible! Here:

Basically you should be able to use what's called the "hold space" to recognise and remember stuff from multiple lines.

Old 01-31-2007, 07:30 AM   #3
LQ Veteran
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381

Your command file should look something like this:


Nick_Battle gave good advice: All the info needed is in the Sed&Awk book.
Old 01-31-2007, 09:00 AM   #4
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 722

Rep: Reputation: 73

I give you no extra magic, however, a rule that works for me is to remember that sed deals with single-lines unless you do some extra work.

I could not get the URL that Nick posted to work ( page deleted ). If you can read Russian, perhaps some of the links at that top page might help.

There are some other places to look. The web page has a number of links that may help.

It is difficult to imagine a better reference than O'Reilly's sed and awk. I use the 2nd edition (page 107 ff for your circumstance); you might be able to pick up a used version someplace of either edition 1 or 2. I think sed is very useful in many situations, however, perl has probably taken over much of the new work for which sed had been used.

Best wishes ... cheers, makyo



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
Remove string in sed twantrd Programming 7 09-13-2006 02:28 PM
How can I replace this string with another using sed? dave4545 Programming 7 01-27-2006 10:58 AM
insert string with sed greg108 Programming 7 02-18-2005 01:11 PM
[sed] replace string? chuanyung Programming 3 03-11-2004 08:42 PM
need help substituting with sed parker Programming 2 08-08-2003 10:03 AM

All times are GMT -5. The time now is 07:45 AM.

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