LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 07-18-2011, 08:31 AM   #1
XXLRay
Member
 
Registered: May 2010
Posts: 133

Rep: Reputation: 16
How to escape single quotes in sed for multi line pattern


I have some code written in VHDL that looks as follows:
Code:
foo = "bar";
  foo <= 'bar',

foo : bar
The pattern "foo = "bar";\n foo <= 'bar'," needs to be replaced (but no other patterns in this file). Thus the result is supposed to be:
Code:
foobar

foo : bar
I tried the following commands:
Code:
sed -i ':a $!{N;ba}; s/foo = "bar";[\n ]*foo <= 'bar',/foobar/g' myfile
sed -i ':a $!{N;ba}; s/foo = "bar";[\n ]*foo <= \'bar\',/foobar/g' myfile
sed -i ':a $!{N;ba}; s/foo = "bar";[\n ]*foo <= [\']bar[\'],/foobar/g' myfile
sed -i ':a $!{N;ba}; s/foo = "bar";[\n ]*foo <= "'"bar"'",/foobar/g' myfile
sed -ir ':a $!{N;ba}; s/foo = "bar";[\n ]*foo <= 'bar',/foobar/g' myfile
sed -ir ':a $!{N;ba}; s/foo = "bar";[\n ]*foo <= \'bar\',/foobar/g' myfile
sed -ir ':a $!{N;ba}; s/foo = "bar";[\n ]*foo <= [\']bar[\'],/foobar/g' myfile
sed -ir ':a $!{N;ba}; s/foo = "bar";[\n ]*foo <= "'"bar"'",/foobar/g' myfile
sed -i ':a $!{N;ba}; s/foo = "bar";[\n ]*foo <= /foobar/g' myfile works without problems. The trouble occurs on the first single quote.

Any hints?
 
Old 07-18-2011, 08:35 AM   #2
XXLRay
Member
 
Registered: May 2010
Posts: 133

Original Poster
Rep: Reputation: 16
Solved it by myself just seconds later. I need to end the single quoted string, escape the single quote and start the single quoted string again:
Code:
sed -i ':a $!{N;ba}; s/foo = "bar";[\n ]*foo <= '\''bar'\'',/foobar/g' myfile
 
  


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
[SOLVED] sed to display the pattern string, the line above it and the first line of that para rockie321 Linux - Newbie 3 04-03-2011 03:48 PM
[SOLVED] Regx: Multi line pattern matching angel115 Programming 15 01-04-2011 12:43 PM
multiple pattern search in a single file line by line saheervc Linux - Newbie 2 09-02-2010 12:45 AM
replace a pattern with a line using sed/awk lokeshn05 Linux - Newbie 3 05-06-2009 04:01 PM
sed display line after pattern match inonzi_prowler Linux - Software 3 02-19-2007 02:47 PM

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

All times are GMT -5. The time now is 01:44 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