LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 02-25-2012, 05:22 PM   #1
casperdaghost
Member
 
Registered: Aug 2009
Posts: 349

Rep: Reputation: 16
using sed replace command with HTML brackets


I want to replace the angle brackets in this text.
Code:
<body> 
<p>
Here is some normal text
</p>
<span class="bigText">Monster Text!</span> 
<p>
Next to the big text 
</p>
so i figures i would use the sed replace commands however it does not replae the while tag - I get <lt; - it is skipping the ampersand and retaining the angle bracket - not replacing it.
Code:
more more_body | sed -e 's/</&lt;/g'


<lt;body> 

<lt;p>
Here is some normal text
<lt;/p>

<lt;span class="bigText">Monster Text!<lt;/span> 

<lt;p>
Next to the big text 
<lt;/p>

********
This is what I want it to look like :
Code:
&lt;body> 

&lt;p>
Here is some normal text
&lt;/p>

&lt;span class="bigText">Monster Text!&lt;/span> 

&lt;p>
Next to the big text 
&lt;/p>
I want the less than angle brackets replaces with the the html entity - &lt;

Last edited by casperdaghost; 02-25-2012 at 05:29 PM.
 
Old 02-25-2012, 05:36 PM   #2
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
& has special meaning in sed, you have to escape it
Code:
sed 's/</\&lt;/g' file...
man sed
Code:
...
s/regexp/replacement/
              Attempt  to match regexp against the pattern space.  If success-
              ful,  replace  that  portion  matched  with  replacement.    The
              replacement may contain the special character & to refer to that
              portion of the pattern space  which  matched,  and  the  special
              escapes  \1  through  \9  to refer to the corresponding matching
              sub-expressions in the regexp.

Last edited by Cedrik; 02-25-2012 at 05:37 PM.
 
  


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 command to replace file extension leighya Linux - Newbie 18 04-22-2012 04:20 AM
[SOLVED] sed command to replace special character / Lokelo Linux - Newbie 11 11-23-2011 08:59 AM
Sed and brackets unihiekka Linux - Newbie 9 10-10-2010 12:08 AM
sed command to replace slash with backslash stelmed Slackware 13 08-19-2010 06:01 AM
sed - find and replace command bullshit Programming 9 01-05-2006 04:25 AM


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