regex - using sed to insert whitespaces between a number and word -


i have series of files uses fixed delimiting, instead of comma separated delimiting. this:

2015/09/29 659027 rih619 25 105.80in921186 2015/09/29 659027 rih619 25 105.80in921186 2015/09/29 659027 rih619 25 105.80in921186 2015/09/29 659027 rih619 25 105.80in921186 

i replace spaces commas. have piece of code accomplish this:

sed -r 's/^\s+//;s/\s+/,/g' 

after running code result:

2015/09/29,659027,rih619,25,105.80in921186 2015/09/29,659027,rih619,25,105.80in921186 2015/09/29,659027,rih619,25,105.80in921186 2015/09/29,659027,rih619,25,105.80in921186 

my problem files doesn't have space between amount , reference. output needs this:

2015/09/29,659027,rih619,25,105.80,in921186 2015/09/29,659027,rih619,25,105.80,in921186 2015/09/29,659027,rih619,25,105.80,in921186 2015/09/29,659027,rih619,25,105.80,in921186 

what tried is:

sed -r 's/^\s+//;s/\.\d\d\d+/\.\d\d,\d/;s/\s+/,/g' 

but didn't seem anything

with tr , sed

 tr ' ' ',' <file | sed -r 's/(\.[0-9]{2})/\1,/' 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -