Home > front end >  How to replace text in multiple xml files in Linux
How to replace text in multiple xml files in Linux

Time:04-11

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

CodePudding user response:

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
  • Related