I have something like below in my sample.xml file, and want to extract the value which is in version tag only when the artifactId is app1 as we would be having the multiple same set of tags with different artifactId in the given file using shell script.
<groupId>abc.app1</groupId>
<artifactId>app1</artifactId>
<packaging>pom</packaging>
<name>app1 ${version}</name>
<version>1.2.50</version>
My final output would be like below,
variable1=1.2.50
Note that I need to read a file and extract that string.
only when the artifactId is app1 as we would be having the multiple same set of tagsso write code for that. You can use Python or Perl xml modules, there is xmllint and xmlstarlet. Shell has no XML support.