Hammond95
Hammond95

Reputation: 576

Manage XML strings with sed

Hi i'm trying to make some replacements in an XML file using sed, but i think i'm missing something...

The kind of string i'm trying to replace is the follow:

<Field name="ColName" type="java.lang.String"><![CDATA[EXTRACT_DATE]]></Field>

I store it in a variable

F_LEFTSTR="<Field name=\"ColName\" type=\"java\.lang\.String\"><!\[CDATA\["
F_RIGHTSTR="\]\]><\/Field>"
F_RIGHTSTR="<\/Field>"
F_STRTOFIND="$F_LEFTSTR$FLD$F_RIGHTSTR"

and i try to manage special characters using backslash \

sed -i "s/$F_STRTOFIND/REPLACEMENT/" XML.xml

Upvotes: 0

Views: 46

Answers (1)

Jim Garrison
Jim Garrison

Reputation: 86774

Single quotes in the bash command prevent interpolation of shell variables. You'll have to use double quotes and escape the embedded double quotes.

Upvotes: 1

Related Questions