Use bash
You do not need an external program to do this, especially since it appears you want to replace the last period with a dash. Bash can handle string manipulations itself.
Presuming you have
vers='version: 1.8.0.110'
the answer is simply:
$ echo ${vers%.*}-${vers##*.}
1.8.0-110
The % means delete the shortest string to the right that matches. The ## means delete the longest string to the left that matches.
What if there are more than three periods?
If you actually want to replace the third period, not the last period as I presumed above, it gets a little trickier in bash, but it is still possible. For example, if vers='version: 1.8.0.110.hut.hut.hut.hike!'
, you can find everything after the third period and use that to truncate the string:
$ end=${vers#*.*.*.}
$ start=${vers%$end}
$ echo ${start%.}-$end
version: 1.8.0-110.hut.hut.hut.hike!
Another way: use IFS to split string into a bash array
While this is overkill for the question, it is sometimes useful to split a string into components and load them into an array.
IFS=. read -a foo <<<'version: 1.8.0.110.hut.hut.hut.hike!'
You can iterate over the array $foo
and choose what to print when. For example,
echo -n $foo
for ((i=1; i<${foo[@]}; i++)); do
[[ i -eq 3 ]] && echo -n - || echo -n .
echo -n ${foo[i]};
done
echo