Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 02-25-2012, 04:22 PM   #1
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.
Here is some normal text
<span class="bigText">Monster Text!</span> 
Next to the big text 
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.
more more_body | sed -e 's/</&lt;/g'


Here is some normal text

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

Next to the big text 

This is what I want it to look like :

Here is some normal text

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

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

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

Rep: Reputation: 243Reputation: 243Reputation: 243
& has special meaning in sed, you have to escape it
sed 's/</\&lt;/g' file...
man sed
              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 04:37 PM.


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 03:20 AM
[SOLVED] sed command to replace special character / Lokelo Linux - Newbie 11 11-23-2011 07:59 AM
Sed and brackets unihiekka Linux - Newbie 9 10-09-2010 11:08 PM
sed command to replace slash with backslash stelmed Slackware 13 08-19-2010 05:01 AM
sed - find and replace command bullshit Programming 9 01-05-2006 03:25 AM > Forums > Linux Forums > Linux - Newbie

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