Gangmax Blog

How to get pom.xml version by one command

Inspired by here and here.

1
cat pom.xml | grep "^    <version>.*</version>$" | awk -F'[><]' '{print $3}'

Notes:

  1. “cat pom.xml”: print the whole content of the pom.xml file;

  2. “grep “^ <version>.*</version>$””: Get the version line of the pom.xml project. Only the project’s version line has the 4 spaces indent(for the other version lines in the dependencies section have more indent spaces. Good indent is useful here);

  3. “awk -F’[><]’ ‘{print $3}’”: seperate the version line by “<” and “>” and get the version info only without “<version>“ or “</version>“.

Comments