I have file with text as below, I would like get the the version argument, 123abc in below case, the argument can be alphanumric.
sometext -version 123abc -mode xx
Not working:
grep -oP "\S+\s+-version\s+\K(.*)\s+" file
I have file with text as below, I would like get the the version argument, 123abc in below case, the argument can be alphanumric.
sometext -version 123abc -mode xx
Not working:
grep -oP "\S+\s+-version\s+\K(.*)\s+" file
Using any sed:
$ sed 's/.*-version *\([^ ]*\).*/\1/' file
123abc
Trying to use grep -P
to select parts of input lines other than the matching string is just overly complicated IMHO as well as being non-portable.