Problem with 'sed' command while using HTML tags

Hello,

I am using sed as follows -

sed 's/CONTACT SYSTEMS! Some payments have been rejected/<B><font color="red" size="5.0pt"CONTACT SYSTEMS! Some payments have been rejected</font></B>/' $REPORT_FILE

But while executing this, I am getting the error as -
sed: command garbled

& hence the string is not getting replaced with the replacement string in HTML tags. Please help me in this. I am a newbie to using 'sed'.

I am using 'ksh' shell.

Try to escape the non alphanumeric characters in the sed command.

Regards

I tried but it is not working.

I did like this -

sed 's/CONTACT SYSTEMS! Some payments have been rejected/\<B\>\<font color="red" size="5.0pt"\>CONTACT SYSTEMS! Some payments have been rejected\</font\>\</B\>/' $REPORT_FILE

Still got the same error.

Try this:

sed 's/CONTACT SYSTEMS! Some payments have been rejected/<B><font color="red" size="5\.0pt"CONTACT SYSTEMS! Some payments have been rejected<\/font><\/B>/' $REPORT_FILE

I've escaped the "/" and ".".

Regards

Escaping the "." shouldn't be necessary in the replacement string -- it's the "/" characters that were causing the problem because sed uses them to separate the regexp and the replacement in

sed  "s/foo/bar/"

If you can't be bothered to escape all the "/"s, you can just as easily use a different character i.e. the above is equivalent to

sed  "s,foo,bar,"

(I find this useful when using sed on Unix path names.)

Also, you can use "\0" in the replacement string to repeat the matched pattern, e.g.

sed  "s,CONTACT SYSTEMS! Some payments have been rejected/<B><font color="red" size="5.0pt"\0</font></B>,"

Or use a different separator.

sed 's%CONTACT SYSTEMS! Some payments have been rejected%<B><font color="red" size="5.0pt"CONTACT SYSTEMS! Some payments have been rejected</font></B>%' $REPORT_FILE