user3588157
user3588157

Reputation: 11

how to find and replace in unix

I have an XML file having tags <![CDATA[]]> & I need to replace this tag with

 <![CDATA[XXX]]>

when am trying to replace using sed command :sed 's/<![CDATA[]]>/<![CDATA[XXX]]>/g' stores.xml

i can't see any changes on my file.

Please help me in finding the solution.

Upvotes: 0

Views: 108

Answers (1)

Alfe
Alfe

Reputation: 59426

Try this:

sed -i 's/<!\[CDATA\[\]\]>/<!\[CDATA\[XXX\]\]>/g' stores.xml

You need to escape the brackets, otherwise they mean in regexp syntax "any of the enclosed characters".

To see the changes applied to an existing file, use the option -i. Alternatively you can use

sed ... < stores.xml > new_stores.xml

Which, for testing at least, might be more of your taste because it creates a new file with the result and leaves the original untouched. (Use mv new_stores.xml stores.xml afterwards in case the result looks fine.)

Upvotes: 2

Related Questions