Hi there

Yesterday I had to change all CDATA tags in an XML document. The standard procedure used here where I work is a search and replace of <![CDATA[ by <CDATA> and ]]> by </CDATA>.

Although there is an easy way of doing a global search and replace in all files in a directory using JEdit (a nice java multi-purpose editor), there is an even easier way of doing it with a standard Unix tool available in all Linux distributions too (and I think there are versions for Windows too).

First we need to create a file with the replacement instructions. The following two lines would be enough:

The "s" instruction stands for "substitute" and the "g" at the end says to do it globally (otherwise it would replace only the first instance in case there was more than one in a line). Once we have these two lines in a file called, say, "replacement.sed" then from the command line we just need to say
prompt> sed -i~ -f replacement.sed *.xml
and all the tags in the xml files will be replaced in-place, leaving the former files with extension .xml~

I hope this wasn't too technical and that it could be useful for somebody out there.