Reputation: 15844
I have a text which randomly contains some numbers and I want to find them and separate thousands.
Input
Some random text 123456 and other text 987654 etc.
Output
Some random text 123 456 and other text 987 654 etc.
Any help would be appreciated.
Upvotes: 0
Views: 611
Reputation: 65851
The task has some corner cases. My first attempt for integers only would be this recursive GNU sed
command:
sed -r ':a;s/([0-9])([0-9]{3}([^0-9]|$))/\1 \2/;ta'
Demo:
$ echo 'Some random text 123456 and other text 9876522224
5464, 83478234 and 2312.' | sed -r ':a;s/([0-9])([0-9]{3}([^0-9]|$))/\1 \2/;ta'
Some random text 123 456 and other text 9 876 522 224
5 464, 83 478 234 and 2 312.
Upvotes: 3