Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Replace symbols > and < with &lt; and &gt;

821 views
Skip to first unread message

jhabe...@gmail.com

unread,
Apr 16, 2008, 4:27:27 PM4/16/08
to
Is there a method to replace the greater than and less than symbols
with &lt; and &gt; for processing in an XML file? I had tried to use
sed similar to the following but it does not work:

$ echo "test>1w3" |sed 's/>/&gt;/g'
test>gt;1w3

John W. Krahn

unread,
Apr 16, 2008, 4:30:19 PM4/16/08
to

echo "test>1w3" |sed 's/>/\&gt;/g'


John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall

Chris Mattern

unread,
Apr 16, 2008, 5:30:55 PM4/16/08
to

"&" is a special character in the replacement operand of
substitution REs, meaning "what got matched by the match
operand." In this case, that was ">", so "&gt;" becomes
">gt;". You need to escape it to tell sed not to treat it
as a special character:

$ echo "test>1w3" |sed 's/>/\&gt;/g'
test&gt;1w3

--
Christopher Mattern

NOTICE
Thank you for noticing this new notice
Your noticing it has been noted
And will be reported to the authorities

Stephane CHAZELAS

unread,
Apr 17, 2008, 2:21:15 AM4/17/08
to
2008-04-16, 13:27(-07), jhabe...@gmail.com:

If you have GNU recode:

recode ..html

--
Stéphane

0 new messages