I have an xml that looks something like this
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<version>1</version>
</parent>
<version>5</version>
<properties>
<test.version>10</test.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<version>${test.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
My task is to
- change only the version that is there inside parent tag
- change test.version inside properties tag.
My resulting xml should look like
<parent>
<version>2</version> //changed here
</parent>
<version>5<version>
<properties>
<test.version>20</test.version> //changed here
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<version>${test.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
I have tried this using sed for the second requirement.
sed -i '/<test.version>/,/<\/test.version>/s/10/20/' "filename"
assuming all the xml is there in a file
The problem with the above sed command is that it is able to replace 10 with 20. but i want to replace any number with 20. how to do this.
for the first requirement when i am trying to use the same sed command as above all the matching version is being changed. i want only version inside parent to be changed. Again here i want to change anything inside parent/version to say 30