I have a pom.xml
file and I want to replace the version inside any of the dependency
nodes from 0.1-SNAPSHOT
to a different version (let's say NEW-VERSION
), the only restriction I have is that the replacement should be done only if the groupId
matches a particular text, lets say: com.company.xyz
.
That being said, let's say this is the dependencies
section of my pom.xml
:
<dependencies>
<dependency>
<groupId>com.company.xyz</groupId>
<artifactId>xyz-xx-utils</artifactId>
<version>0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.ibm.xyz</groupId>
<artifactId>xyz</artifactId>
<version>56.1</version>
</dependency>
</dependencies>
After applying the sed command I want it to look like:
<dependencies>
<dependency>
<groupId>com.company.xyz</groupId>
<artifactId>xyz-xx-utils</artifactId>
<version>NEW-VERSION</version>
</dependency>
<dependency>
<groupId>com.ibm.xyz</groupId>
<artifactId>xyz</artifactId>
<version>56.1</version>
</dependency>
</dependencies>
Here is what I have tried without any success:
newVersion="NEW-VERSION"
sed -i "s/\(<dependency>\)\(<groupId>com.company.xyz</groupId>\)\(<artifactId>.*\</artifactId>\)\(<version>0.1-SNAPSHOT</version>\)\(</dependency>\)/\1\2\3$newVersion\5/" pom.xml
I was wondering if the reason why this does not work is because my text has multiple lines, so I researched a little bit but I did not understand the syntax used to work with multiple lines (some N
thing).
Btw, I am including this piece of code in a bash file that performs other operations, that is why I want to do this using sed or any other "tool" that is bash compatible.