0

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.

4

1 回答 1

3

该任务有一些极端情况。我对整数的第一次尝试是这个递归GNU sed命令:

sed -r ':a;s/([0-9])([0-9]{3}([^0-9]|$))/\1 \2/;ta'

演示:

$ 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.
于 2013-05-03T22:04:45.487 回答