'increment major and minor version of pom file using sed/awk [closed]

Requirement 1:

Version - 1.0.0
New Version - 2.0.0 
next - 3.0.0. .... so on

Every time only Major version should increase .

Requirement 2:

Example 1

Version - 1.0.0
New Version - 1.1.0 
next - 1.2.0 ... so on

Example 2-

Version - 2.0.0
New Version - 2.1.0 
next - 2.2.0 ... so on

Every time only minor version should increase .

How this can be achieve by sed or awk command.



Solution 1:[1]

$ awk -v i=major '
BEGIN {
    FS=OFS="."
    v["major"]=1               # pick desired version level to increment
    v["minor"]=2               # ... in command line arguments
    v["patch"]=3               # awk -v i=(major|minor|patch) ...
}
{
    $v[i]++
    # for(j=v[i]+1;j<=NF;j++)  # uncomment to reset the lower components to zero
    #     $j=0                 # metoo 
}1' <<< 1.2.3

Output:

2.2.3

or if uncommented the commented out lines of code:

2.0.0

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1