I've got an XML-file with lots of the following code:
<BankAccount code="NL18INGB0001234567">
<BankAccountType code="NL">
<Description/>
I need to replace code="NL"
with code="IBA"
, but only when the BankAccount
has INGB000
in it. I use the following sed command:
sed 'N;s/\(INGB000[0-9].*NL\)/\1_OUD/g;s/NL_OUD/IBA/g' file1.xml > file2.xml
The problem is that this command only replaces the first one but not all the other ones.
I expected the -g
option to do a global match, but that didn't work.
I also tried:
sed ':a;N;ta;s/\(INGB000[0-9].*NL\)/\1_OUD/g;s/NL_OUD/IBA/g' file1.xml > file2.xml
What am I doing wrong?
Input:
<?xml version='1.0' encoding='UTF-8' ?>
<eExact xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="eExact-Schema.xsd">
<Accounts>
<Account code="1206" status="A" type="C">
<Name>John Doe</Name>
<Contacts>
<Contact default="1" gender="M" status="A">
<LastName>Client: 10000</LastName>
<Initials/>
<Addresses>
<Address type="V">
<AddressLine1>one-way-street</AddressLine1>
<PostalCode>1000 AB</PostalCode>
<City>Simcity 1</City>
<Country code="NL"/>
</Address>
</Addresses>
</Contact>
</Contacts>
<Debtor code="1206" number="1206">
<BankAccounts>
<BankAccount code="NL93INGB0001234567">
<BankAccountType code="NL">
<Description/>
</BankAccountType>
<Bank code="">
<Name/>
<IBAN>NL93INGB0001234567</IBAN>
</Bank>
<SDDMandate>
<MndtId>02001234-0000004</MndtId>
<DtOfSgntr>2000-11-01</DtOfSgntr>
<LclInstrm>Core</LclInstrm>
<LastSDDDt/>
</SDDMandate>
</BankAccount>
</BankAccounts>
<SendReminder>1</SendReminder>
</Debtor>
</Account>
<Account code="1123" status="A" type="C">
<Name>Johny Doe</Name>
<Contacts>
<Contact default="1" gender="V" status="A">
<LastName>Client: 10001</LastName>
<Addresses>
<Address type="V">
<AddressLine1>one-way-street</AddressLine1>
<PostalCode>1000 AB</PostalCode>
<City>Simcity 2</City>
<Country code="NL"/>
</Address>
</Addresses>
</Contact>
</Contacts>
<Debtor code="1123" number="1123">
<BankAccounts>
<BankAccount code="NL25RABO0123456789">
<BankAccountType code="NL">
<Description/>
</BankAccountType>
<Bank code="">
<Name/>
<IBAN>NL25RABO0123456789</IBAN>
</Bank>
<SDDMandate>
<MndtId>02001234-0000003</MndtId>
<DtOfSgntr>2000-02-03</DtOfSgntr>
<LclInstrm>Core</LclInstrm>
<LastSDDDt/>
</SDDMandate>
</BankAccount>
</BankAccounts>
<SendReminder>1</SendReminder>
</Debtor>
</Account>
<Account code="1109" status="A" type="C">
<Name>Joan Doe</Name>
<Contacts>
<Contact default="1" gender="V" status="A">
<LastName>Client: 10002</LastName>
<Initials/>
<Addresses>
<Address type="V">
<AddressLine1>one-way-street</AddressLine1>
<PostalCode>1000 AB</PostalCode>
<City>Simcity 1</City>
<Country code="NL"/>
</Address>
</Addresses>
</Contact>
</Contacts>
<Debtor code="1109" number="1109">
<BankAccounts>
<BankAccount code="NL46RABO0123456789">
<BankAccountType code="NL">
<Description/>
</BankAccountType>
<Bank code="">
<Name/>
<IBAN>NL46RABO0123456789</IBAN>
</Bank>
<SDDMandate>
<MndtId>02001234-0000002</MndtId>
<DtOfSgntr>2000-11-01</DtOfSgntr>
<LclInstrm>Core</LclInstrm>
<LastSDDDt/>
</SDDMandate>
</BankAccount>
</BankAccounts>
<SendReminder>1</SendReminder>
</Debtor>
</Account>
<Account code="1631" status="A" type="C">
<Name>Flint</Name>
<Contacts>
<Contact default="1" gender="V" status="A">
<LastName>Client: 10003</LastName>
<Initials/>
<Addresses>
<Address type="V">
<AddressLine1>one-way-street</AddressLine1>
<PostalCode>1000 AB</PostalCode>
<City>Simcity 3</City>
<Country code="NL"/>
</Address>
</Addresses>
</Contact>
</Contacts>
<Debtor code="1631" number="1631">
<BankAccounts>
<BankAccount code="NL10INGB0001234567">
<BankAccountType code="NL">
<Description/>
</BankAccountType>
<Bank code="">
<Name/>
<IBAN>NL10INGB0001234567</IBAN>
</Bank>
<SDDMandate>
<MndtId>02001234-0000001</MndtId>
<DtOfSgntr>2000-07-05</DtOfSgntr>
<LclInstrm>Core</LclInstrm>
<LastSDDDt/>
</SDDMandate>
</BankAccount>
</BankAccounts>
<SendReminder>1</SendReminder>
</Debtor>
</Account>
</Accounts>
</eExact>
Desired output
<?xml version="1.0" encoding="UTF-8"?>
<eExact xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="eExact-Schema.xsd">
<Accounts>
<Account code="1206" status="A" type="C">
<Name>John Doe</Name>
<Contacts>
<Contact default="1" gender="M" status="A">
<LastName>Client: 10000</LastName>
<Initials/>
<Addresses>
<Address type="V">
<AddressLine1>one-way-street</AddressLine1>
<PostalCode>1000 AB</PostalCode>
<City>Simcity 1</City>
<Country code="NL"/>
</Address>
</Addresses>
</Contact>
</Contacts>
<Debtor code="1206" number="1206">
<BankAccounts>
<BankAccount code="NL93INGB0001234567">
<BankAccountType code="IBA">
<Description/>
</BankAccountType>
<Bank code="">
<Name/>
<IBAN>NL93INGB0001234567</IBAN>
</Bank>
<SDDMandate>
<MndtId>02001234-0000004</MndtId>
<DtOfSgntr>2000-11-01</DtOfSgntr>
<LclInstrm>Core</LclInstrm>
<LastSDDDt/>
</SDDMandate>
</BankAccount>
</BankAccounts>
<SendReminder>1</SendReminder>
</Debtor>
</Account>
<Account code="1123" status="A" type="C">
<Name>Johny Doe</Name>
<Contacts>
<Contact default="1" gender="V" status="A">
<LastName>Client: 10001</LastName>
<Addresses>
<Address type="V">
<AddressLine1>one-way-street</AddressLine1>
<PostalCode>1000 AB</PostalCode>
<City>Simcity 2</City>
<Country code="NL"/>
</Address>
</Addresses>
</Contact>
</Contacts>
<Debtor code="1123" number="1123">
<BankAccounts>
<BankAccount code="NL25RABO0123456789">
<BankAccountType code="NL">
<Description/>
</BankAccountType>
<Bank code="">
<Name/>
<IBAN>NL25RABO0123456789</IBAN>
</Bank>
<SDDMandate>
<MndtId>02001234-0000003</MndtId>
<DtOfSgntr>2000-02-03</DtOfSgntr>
<LclInstrm>Core</LclInstrm>
<LastSDDDt/>
</SDDMandate>
</BankAccount>
</BankAccounts>
<SendReminder>1</SendReminder>
</Debtor>
</Account>
<Account code="1109" status="A" type="C">
<Name>Joan Doe</Name>
<Contacts>
<Contact default="1" gender="V" status="A">
<LastName>Client: 10002</LastName>
<Initials/>
<Addresses>
<Address type="V">
<AddressLine1>one-way-street</AddressLine1>
<PostalCode>1000 AB</PostalCode>
<City>Simcity 1</City>
<Country code="NL"/>
</Address>
</Addresses>
</Contact>
</Contacts>
<Debtor code="1109" number="1109">
<BankAccounts>
<BankAccount code="NL46RABO0123456789">
<BankAccountType code="NL">
<Description/>
</BankAccountType>
<Bank code="">
<Name/>
<IBAN>NL46RABO0123456789</IBAN>
</Bank>
<SDDMandate>
<MndtId>02001234-0000002</MndtId>
<DtOfSgntr>2000-11-01</DtOfSgntr>
<LclInstrm>Core</LclInstrm>
<LastSDDDt/>
</SDDMandate>
</BankAccount>
</BankAccounts>
<SendReminder>1</SendReminder>
</Debtor>
</Account>
<Account code="1631" status="A" type="C">
<Name>Flint</Name>
<Contacts>
<Contact default="1" gender="V" status="A">
<LastName>Client: 10003</LastName>
<Initials/>
<Addresses>
<Address type="V">
<AddressLine1>one-way-street</AddressLine1>
<PostalCode>1000 AB</PostalCode>
<City>Simcity 3</City>
<Country code="NL"/>
</Address>
</Addresses>
</Contact>
</Contacts>
<Debtor code="1631" number="1631">
<BankAccounts>
<BankAccount code="NL10INGB0001234567">
<BankAccountType code="IBA">
<Description/>
</BankAccountType>
<Bank code="">
<Name/>
<IBAN>NL10INGB0001234567</IBAN>
</Bank>
<SDDMandate>
<MndtId>02001234-0000001</MndtId>
<DtOfSgntr>2000-07-05</DtOfSgntr>
<LclInstrm>Core</LclInstrm>
<LastSDDDt/>
</SDDMandate>
</BankAccount>
</BankAccounts>
<SendReminder>1</SendReminder>
</Debtor>
</Account>
</Accounts>
</eExact>
This doesn't work:
sed '/BankAccount.*INGB000/,$ s/BankAccountType code="NL"/BankAccountType code="IBA"/g' file1.xml > file2.xml
This replaces all the code=NL after the first INGB000.