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
2

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.