... * too greedy in sed
I want to extract the version number from multiple lines in bash without using too many additional packages. So far I've tried sed
.
Here is the API:
3.81-8.1ubuntu1.1 should give : 3.81
2.68-1ubuntu2 should give : 2.68
1:1.11.3-1ubuntu2 should give : 1.11.3
And here is my sed command:
echo ... | sed -r 's/.*([0-9\.]+).*/\1/'
However, the discovery is .*
too greedy, especially in the latter case. I have tried several .*?
and .\{-}
with no success.
I can do it in two passes, but I'd rather learn to do it in one.
+3
source to share