Issue
I know how to receive the latest git version by using git describe --tags --abbrev=0
. However in my special case I need the version ONE before.
If the latest version is v0.0.3
I need to get v0.0.2
for instance.
I tried to find a way to do so but my shell/git magic is weak.
Solution
With awk
along with your git
command could you please try following.
git describe --tags --abbrev=0 | awk 'BEGIN{FS=OFS="."} {$NF-=1} 1'
Explanation: Passing git
command's output to awk
command as an input. In awk
code BEGIN
section setting field separator and output field separator as .
for all lines. Then in main program deceasing 1
in last field of current line. 1
is one of the ways in awk
to print current line.
Answered By - RavinderSingh13 Answer Checked By - David Goodson (WPSolving Volunteer)