0

I try to increment a version number that look like this 0.0.1-pre. I would like to increment the third column. The result should look like this:

0.0.2-pre
0.0.3-pre
0.0.4-pre
0.0.5-pre
.........

i would like to have something like echo 0.0.1-pre | awk 'BEGIN{x=0;FS=OFS="."} NF>1{$3=$3+x;x++}1'

  • 2
    What should happen with `0.0.9-pre`? `0.0.10-pre` or `0.1.0-pre`? – Cyrus May 13 '20 at 12:05
  • Your input is a single version number, but the output should be a list. How long is this list supposed to be? Is there another parameter which specifies the number of steps or an upper version-limit? – Socowi May 13 '20 at 12:18
  • Does this answer your question? [How to increment version number in a shell script?](https://stackoverflow.com/questions/8653126/how-to-increment-version-number-in-a-shell-script) – Léa Gris May 13 '20 at 14:35

2 Answers2

0

With brace expansion of bash

printf '%s\n' 0.0.{2..10}-pre
  • See the local section of the bash manual PAGER='less +/^[[:blank:]]*Brace\ Expansion' man bash
Jetchisel
  • 7,493
  • 2
  • 19
  • 18
0

If you are interested in a pure bash solution for incrementing the third number (patch) of a string containing a version number (in the format major.minor.patch-release), try:

version=0.0.2-pre

release=${version##*-}
major_minor_patch=${version%-*}
major_minor=${major_minor_patch%.*}
patch=${major_minor_patch##*.}

echo old version: $major_minor.$patch-$release
((patch++))
echo new version: $major_minor.$patch-$release

The output is:

old version: 0.0.2-pre
new version: 0.0.3-pre
Pierre François
  • 5,850
  • 1
  • 17
  • 38