Question

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!

Était-ce utile?

La solution

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.

Autres conseils

You may try Perl regular expressions:

grep -Po "(\d+\.)+\d+"
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top