(a) 0.2.0-123-g9e17591
(b) 0.2.0-g9e17591
- How to get 0.2.0-123 and 0.2.0 respectively ?
- How to extract number 0 & 123 from "0.2.0-123-g9e17591" and 2 & 0 from "0.2.0-g9e17591"
You could use
$ IFS='-' read -ra PARTS <<< 0.2.0-123-g9e17591
$ echo ${PARTS[*]}
to split the string into array PARTS
, with -
as a field separator, and then check the results.
Then you could proceed similarly with the first element of array PARTS
$ IFS='.' read -ra PARTS2 <<< ${PARTS[0]}
$ echo ${PARTS2[*]}
Repeat the operation as needed.
Sources
echo "0.2.0-123-g9e17591" | grep -Eo "(^[0-9]+\.)([0-9]+\.)([0-9]+\-)([0-9]+)"
and thisecho "0.2.0-g9e17591" | grep -Eo "(^[0-9]+\.)([0-9]+\.)([0-9]+)"
and please make your question more clear. – Raffa Mar 13 '21 at 03:59