Parameter expansion seems to be the order of the day.
$ string="toto.titi.12.tata.2.abc.def" $ read num1 num2 <<<${string//[^0-9]/ } $ echo "$num1 / $num2" 12 / 2
This, of course, depends on the format of $string . But at least for the example you provided, it works.
It could be higher than awb's solution for anubhava, which requires a subshell. I also like the chepner solution, but regular expressions are βheavierβ than parameter extensions (although obviously more accurate). (Note that in the expression above, [^0-9] may look like an atom of regular expressions, but it is not.)
You can read about this form or parameter extension in the bash man page. Note that ${string//this/that} (as well as <<< ) is a bagism and is not compatible with traditional Bourne or posix shells.
ghoti source share