Skip to content

substitution on a XML file shell script snippet

One more Shell script snippet.

Scenario: I have several directories, each one with a file called strings.xml. The problem with those files is that they are like:


I’d like to remove those double quotation marks inside the string element.

I’m already in the directory which contains all others directories with the xml files.

Solution: A script that for each directory, cat it xml file and substitute the occurrences of >” for > and “< for <.

for file in `ls`; do cat $file/strings.xml| sed ‘s/>”/>/g’| sed ‘s/” $file/strings.xml; done

Warning: Shell script and regular expressions are not the correct way to parse XML because there are special cases where you can not handle properly. But in simple cases like this one it can be useful.

Published inenglish

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *