LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-19-2011, 06:29 AM   #1
guessity
Member
 
Registered: Dec 2009
Posts: 41

Rep: Reputation: 15
Question Sed replace Help for = and quote


I am trying to replace <p align='justify'> with <p> irrespective of the case for the following text
Code:
<description><![CDATA[
<p align='justify'>
World
</p><p align='justify'>
Round
</p><p align='justify'>
Go
</p>
Ram]]></description>
and I am doing it with sed with the following command -

Code:
find /home/test/ -type f -exec sed -i 's#/<p align/=/'justify/'/>#/<p/>#g' {} \;
Any idea where have I gone wrong as nothing is changing for the text I desire.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 10-19-2011, 07:27 AM   #2
miguel.axcar
LQ Newbie
 
Registered: Oct 2011
Posts: 2

Rep: Reputation: Disabled
Mate, try this on your sed parameter, using sharp as separator as you did:

sed "s#<p align='justify'>#<p>#g"

Cheers,

Luiz Miguel Axcar
miguel@axcar.com.br
Bauru, São Paulo, Brasil
 
1 members found this post helpful.
Old 10-19-2011, 07:29 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
You used some extra slashes that are not matched. Moreover, since you have single quotes in the pattern, you need to embed the sed command into double quotes. Try this:
Code:
find /home/test -type f -exec sed -i "s#<p align='justify'>#<p>#g" {} \;
 
2 members found this post helpful.
Old 10-19-2011, 07:34 AM   #4
guessity
Member
 
Registered: Dec 2009
Posts: 41

Original Poster
Rep: Reputation: 15
Thanks. It worked well.

Quote:
Originally Posted by colucix View Post
You used some extra slashes that are not matched. Moreover, since you have single quotes in the pattern, you need to embed the sed command into double quotes. Try this:
Code:
find /home/test -type f -exec sed -i "s#<p align='justify'>#<p>#g" {} \;

Last edited by guessity; 10-19-2011 at 07:37 AM.
 
Old 10-19-2011, 08:19 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,550

Rep: Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898
Also, assuming the pattern always has the space and the ones you want to keep don't, you could just go:
Code:
find /home/test -type f -exec sed -i 's/<p [^>]*>/<p>/' {} \;
 
  


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
find or replace without using sed adarshmca Linux - Newbie 9 12-28-2010 06:41 AM
sed : Convert double quote to singe quote pgb_710 Programming 6 01-21-2010 08:59 AM
when to quote or not to quote variable names - mktemp problem glinux Linux - Newbie 3 02-20-2009 05:37 PM
How do I replace ' with sed.... @ngelot Linux - Newbie 2 11-02-2007 08:04 PM
insert a single quote is text file with sed eln01 Programming 7 05-10-2007 12:02 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:00 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration