0

I need to extract version number from the following strings .

pattern looks like this.

by using shell script

VAR1=1.1-g13ab57737123
Output 1.1

VAR1=1.2-g328891ahqq12
Output 1.2

VAR1=2.3-g123900a12328
Output 2.3


VAR2=abcd960_1.1-g13ab57737123
Output 1.1
lenik
  • 22,629
  • 4
  • 31
  • 41

1 Answers1

0

This works:

$ VAR1=1.1-g13ab57737123
$ echo $VAR1
1.1-g13ab57737123
$ echo $VAR1 | grep -o "[0-9]\.[0-9]"
1.1

Or if you need longer numbers:

$ VAR1=1.1234-g13ab57737123
$ echo $VAR1 | grep -o "[0-9]\+\.[0-9]\+"
1.1234
lenik
  • 22,629
  • 4
  • 31
  • 41