Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sed Extract version number from string (only version, without other numbers)

I want to achieve the same as explained in sed: Extract version number from string, but taking into consideration only the first sequence of numbers or even safer, tell sed to keep only the sequence of numbers following the name of the command, leaving out the rest.

I have: Chromium 12.0.742.112 Ubuntu 11.04

I want: 12.0.742.112

Instead of: 12.0.742.11211.04

I now know that using head or tail with sort it is possible to display the largest/smallest number, but how can I tell sed to consider the first sequence only?

EDIT: I forgot to mention that I'm using bash.

like image 665
octosquidopus Avatar asked Nov 30 '22 03:11

octosquidopus


1 Answers

The first number? How about:

sed 's/[^0-9.]*\([0-9.]*\).*/\1/'
like image 192
Beta Avatar answered Dec 01 '22 17:12

Beta