Replace space with a comma on Unix

Aliencenet
Aliencenet used Ask the Experts™
on
Hi i have an ASCII file that i need to convert to .csv. Data looks like this:

text1   text2           text3  text5 text6       text7

i would like to replace spaces with a comma so it looks like this:
text1,text2,text3,text5,text6,text7

thanks!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
ozo
Most Valuable Expert 2014
Top Expert 2015
Commented:
sed 's/  */,/g' <ASCII > .csv

Author

Commented:
it gave me this:
,c,o,l,u,m,n,1,c,o,l,u,m,n,2,c,o,l,u,m,n,3,c,o,l,u,m,n,4,c,o,l,u,m,n,5,
ozo
Most Valuable Expert 2014
Top Expert 2015
Commented:
You propably omitted one of the two spaces in 's/  */,/g
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

Author

Commented:
hmmm wierd...
sed 's/ */,/g' conv_test
gives out the same thing.
this worked:
sed 's/[ ][ ]*/,/g'

Author

Commented:
thanks!
Most Valuable Expert 2013
Top Expert 2013

Commented:
A way to avoid using an intermediate file (not every 'sed' understands '-i') -
while read line ; do echo $line ; done < ASCII_file | tr " " "," > ASCII_file
Works also with <TAB>, not only <SPACE>.
wmp
ozo
Most Valuable Expert 2014
Top Expert 2015

Commented:
Every version of perl understands -i

perl -i.bak -lpe "s/\s+/,/"  ASCII_file

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial