I'm newbie in 'sh'. Is it possible to:
#!/usr/bin/env ruby
i=123
i.to_s.split('').join('.') #=> "1.2.3"
I've tried something but didn't succeed:
i=123
IFS='' read -a array <<< "$i"
echo $array #=> "123"
You could use fold and paste:
$ i=123
$ echo $i | fold -w1 | paste -sd.
1.2.3
$ i=1234567890
$ echo $i | fold -w1 | paste -sd.
1.2.3.4.5.6.7.8.9.0
Try this:
sed -r 's/\B/./g' <<< "$i"
Your sed needs to be able to handle extended regular expressions (option -r) for this, though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With