Ubuntu – Extract number from string

12.04command linescripts

When using this ubuntu command:

${HOME}/temp/.git describe --always --tags HEAD 

the output of this command is:

v0.1.5-2-p343h3d3

I want to extract 1.5 from the output above and check if it's greater than 1.5 or not.
Is there any solution for this.?

Best Answer

You could do something like

${HOME}/temp/.git describe --always --tags HEAD  | awk ' {
                             match ($0, /[0-9]+\.[0-9]+\.[0-9]+/,m)
                             if(m[0]>"0.1.5"){ 
                                 print("hello")
                              }
                             }'

This will check the first matching regex result. Just throwing another way to do this, although I'm not sure how much of a practical way this is for you.

Cheers

Related Question