Removing empty spaces and adding commas

I have a file which contains numbers as follows:

1234 9876  6789    5677   3452   
9087   4562   1367   2678  7891

I need to remove the empty spaces and add commas between the numbers like:

1234,9876,6789,5677,3452,   
9087,4562,1367,2678,7891

Can anyone tell me the command to do the same?

Thankx

$ cat sample
1234 9876  6789    5677   3452
9087   4562   1367   2678  7891
$ sed 's/\( \)\{1,\}/,/g' sample
1234,9876,6789,5677,3452,
9087,4562,1367,2678,7891
$

or

$ sed 's/ \+/,/g' sample
1234,9876,6789,5677,3452,
9087,4562,1367,2678,7891

HTH,
Mona

It is not working :frowning:

cat filename | tr -s " " ","

Note: In the first quotes, there is space

Thanku All