Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

use sed to append expression with '<' or '>'

Status
Not open for further replies.

kevpho

Programmer
Jun 9, 2003
47
CA
hi,

i am trying to append some xml script to part of a file using sed, but i cannot use the < or > characters because they are special characters. i can't escape them to \< or \> either because those are also special characters. does anyone know how to append these characters? here is an example of what i need to do:

change 'Hello' to '<Greeting>Hello</Greeting>'

sed -e /Hello/a\<Greeting>Hello<\/Greeting> hello.txt > hello.xml

(the sed command obviously doesn't work)

thanks and best regards,

kevin
 
And what about the use of single quotes ?
sed -e '/Hello/a\
<Greeting>Hello</Greeting>' hello.txt > hello.xml

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
single quotes did not work, but the same command using double quotes worked perfectly, i.e. sed -e "/Hello/a\
<Greeting>Hello</Greeting>" hello.txt > hello.xml


thanks for your help.

kevin
 
single quotes did not work
Really ? Which shell ?
Worked for me in ksh
 
in all honesty i'm not sure what shell it's running on, i'm just running a windows batch file with the sed script inside it.
 
i'm just running a windows batch file
So, why posting in the UNIX Scripting Forum ?
 
because it seemed more of a unix scripting thing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top