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

Is there a method to replace the greater than and less than symbols
with < and > 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/>/>/g'
test>gt;1w3
jhaberla99 [ Mi, 16 April 2008 22:27 ] [ ID #1943341 ]

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

jhaberla99 [at] gmail.com wrote:
> Is there a method to replace the greater than and less than symbols
> with < and > 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/>/>/g'
> test>gt;1w3

echo "test>1w3" |sed 's/>/\>/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
someone [ Mi, 16 April 2008 22:30 ] [ ID #1943342 ]

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

On 2008-04-16, jhaberla99 [at] gmail.com <jhaberla99 [at] gmail.com> wrote:
> Is there a method to replace the greater than and less than symbols
> with < and > 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/>/>/g'
> test>gt;1w3
>

"&" 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 ">" becomes
">gt;". You need to escape it to tell sed not to treat it
as a special character:

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



--
Christopher Mattern

NOTICE
Thank you for noticing this new notice
Your noticing it has been noted
And will be reported to the authorities
Chris Mattern [ Mi, 16 April 2008 23:30 ] [ ID #1943343 ]

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

2008-04-16, 13:27(-07), jhaberla99 [at] gmail.com:
> Is there a method to replace the greater than and less than symbols
> with < and > 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/>/>/g'
> test>gt;1w3

If you have GNU recode:

recode ..html

--
Stéphane
Stephane CHAZELAS [ Do, 17 April 2008 08:21 ] [ ID #1944243 ]
Linux » comp.unix.shell » Replace symbols > and < with &lt; and &gt;

Vorheriges Thema: grouping in awk
Nächstes Thema: simple makefile help