1

I have a file that contains something like this:

VERSION = 1.1.1
version = 1.1.1
VERSION = "1.1.1"
VERSION = '1.1.1"

etc

I am trying to grep for the version number, using this:

grep -E "(VERSION|version|Version)[^0-9]*([0-9]+\.[0-9,A-Z,a-z]+\.[0-9,a-z,A-Z]+)" -oP setup.py

This complains that 'conflicting matchers specified'. Presumably because there are two capturing groups. I have tried to make the first group non-capturing: (?:VERSION|version|Version), but this gives the same error. The version with the non-capturing group does work when tested on regex101 (https://regex101.com/r/21Pkp2/1), so I'm not sure why it doesn't work in grep.

3
  • You cannot use E (ERE) and -P (perl mode) together
    – anubhava
    Commented Nov 25, 2019 at 14:59
  • Oh, removing -E results in it no longer erroring, but printing the whole line, instead of just the capture group Commented Nov 25, 2019 at 15:02
  • You may just use: grep -ioP "version\D*\K(\d+\.[\d,A-Z,a-z]+\.[\d,a-z,A-Z]+)" file
    – anubhava
    Commented Nov 25, 2019 at 15:02

1 Answer 1

3

You cannot use -E (ERE) and -P (perl mode) options together in gnu grep. If you are using gnu grep then just stick with -P and use this command to get all version numbers:

grep -ioP "version\D*\K(\d+\.[\d,A-Z,a-z]+\.[\d,a-z,A-Z]+)" file

1.1.1
1.1.1
1.1.1
1.1.1
  • -i is used for ignore case match.
  • \K is PCRE directive to discard previously matched info
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.