Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

egrep match version number using grep

If I have a string as follows: DATABASE PATCH FOR EORQ (JAN2014 - 11.2.0.4.1)

How would I go about matching the version number? I.e. I would like to extract 11.2.0.4.1. I would like to avoid using sed and awk, as the line is arbitrary, and may change in the future, so I am looking for something which would match a version word containing digits as well as .'s.

I tried to use egrep as follows: egrep -o "[0-9.]{1,}" But it returns

2014

11.2.0.4.3

Thanks!

like image 281
AkshaiShah Avatar asked Dec 07 '22 02:12

AkshaiShah


1 Answers

You can probably use:

$ egrep -o "([0-9]{1,}\.)+[0-9]{1,}" file
11.2.0.4.1
  • ([0-9]{1,}\.)+ matches at least one block of [0-9]{1,} and a dot ..
  • [0-9]{1,} matches a block of [0-9].

So this will match any block of XX.YY, being XX any amount of blocks of ZZ.KK.TT. and so on.

like image 134
fedorqui 'SO stop harming' Avatar answered Dec 20 '22 23:12

fedorqui 'SO stop harming'