Imagine I have the following piece of text:
<Data>
<Country>
<Name>Portugal<\Name>
<Population>10M</Population>
<Sub>
<Code>Y</Code>
</Sub>
</Country>
<Country>
<Name>Spain<\Name>
<Population>30M</Population>
<Sub>
<Code>Y</Code>
</Sub>
</Country>
</Data>
How can I replace the Y
to N
from Country Portugal without replacing the Code from the remaining countries?
I've tried to use sed:
sed -i '/<Country>Portugal<\/Country>/{s/Y/N/;}' file.xml
but this is not replacing anything.
Can you tell me what I am doing wrong? How can I replace the first occurrence of Y
AFTER matching the Portugal ?
Thanks!