• Uncategorized

About linux : How-to-replace-text-in-multiple-xml-files-in-Linux

Question Detail

I have below xml header :

<wechselkurse xmlns:xsi="https://www.bnd-rates.ezv.admin.ch/monthly" xsi:schemaLocation="https://www.bnd-rates.ezv.admin.ch/monthlyrates.xsd">

And i want to replace header in multiple xml files with :

<wechselkurse xmlns="http://www.ps.ezv.admin.ch/apps/rates" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.ps.ezv.admin.ch/apps/rates/monthlyrates.xsd">

I tried below find command , the command didnt throw an error but it didnt even worked:

sed -i "s#<wechselkurse xmlns:xsi="https://www.bnd-rates.ezv.admin.ch/monthly" xsi:schemaLocation="https://www.bnd-rates.ezv.admin.ch/monthlyrates.xsd">#<wechselkurse xmlns="http://www.ps.ezv.admin.ch/apps/rates" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.ps.ezv.admin.ch/apps/rates/monthlyrates.xsd">#" *.xml

Question Answer

Since the replacement in your sed command uses double quotes, you should surround the command with single quotes.

sed -i 's#<wechselkurse xmlns:xsi="https://www.bnd-rates.ezv.admin.ch/monthly" xsi:schemaLocation="https://www.bnd-rates.ezv.admin.ch/monthlyrates.xsd">#<wechselkurse xmlns="http://www.ps.ezv.admin.ch/apps/rates" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.ps.ezv.admin.ch/apps/rates/monthlyrates.xsd">#' *.xml

You may also like...

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.