Editing Commas in a textfile using sed

Hi guys
task removing the last commas of 5th and 6th columns. The bug in the script is causing effect because of whitespaces around commas. I tried to delete white spaces first and running the above script. but still some where getting the results wrong.

I already have a script to do this task but somewhere bug located in the script. Could please debug it. Thanx

script

sed -e 's/,[^0-9]//g' -e 's/,$//g' file_name

input

 
7829885 7831552 + 1    1667,               0,
35934936 35937087 - 2  1281,870,       0,1281,
35934936 35937087 - 2  1281, 870,      0 ,1281 ,
35934936 35937087 - 2  1281 , 870 ,    0, 1281 ,

output should be like this

 
7829885 7831552 + 1 1667 0
35934936 35937087 - 2 1281,870   0,1281
35934936 35937087 - 2 1281,870   0,1281
35934936 35937087 - 2 1281,870   0,1281

The first line of expected output does not follow the same rules for output as do lines 2 .. 4
It has all commas removed. Please clarify.

The first line of expected output does not follow the same rules for output as do lines 2 .. 4
It has all commas removed. Please clarify.

Need to remove the commas of last number like 870 in the 5th column or 1281 in the 6th column. other commas have to stay as it is.

somewhat ugly:

sed 's/ *, */,/g;s/,$//;s/,/ /2;s/,/ /3;/+/s/,/ /1' myFile

Thanx for effort even though its ugly
What if the it not just about 5th and 6th columns. If they happen to appear in 7th and 8th columns is the same code applies?

---------- Post updated at 05:56 AM ---------- Previous update was at 05:53 AM ----------

I think its working perfect. If you explain the code that really helpful to me and others so that we could play with the script for other requirements.
Thanx

s/ *, */,/g
squish all '<space>,<space>' to ','
s/,$//
remove all trailing ',' from end of lines
s/,/ /2
substitute the SECOND occurrence of ',' with '<space>'
s/,/ /3
substitute the THIRD occurrence of ',' with '<space>'
/+/s/,/ /1
on all the lines having '+', substitute the FIRST occurrence of ',' with '<space>'

Hey I have just seen your post.Thanx for your valuable time
You are mentioning 1st and sec occurrences...
The column may be contain so many numbers with commas. still does it work for all numbers??
like 1,2,3,4,5,6,7 and so on like in those columns I specified before?

I tried a sample its working fine for multiple numbers with commas also. I think its fine. What do you say?

The 'solution' was presented for a given SAMPLE file format - YMMV for other 'formats'.

different input
Could you plz suggest modification
How could I modify the code for this kind of input

7829885 7831552 + 1    1667,               0,
35934936 35937087 - 2  1281,870,       0,1281, 120000, 1444444,1111, 333333333 , 2222, 44444, 6666666 ,  555555
35934936 35937087 - 2  1281, 870,      0 ,1281 ,
35934936 35937087 - 2  1281 , 870 ,    0, 1281 ,

---------- Post updated at 07:40 PM ---------- Previous update was at 07:37 PM ----------

I mean what if the column has multiple values (occurences) with commas

what's the desired output given that sample input?

Desired output

7829885 7831552 + 1    1667               0
35934936 35937087 - 2  1281,870       0,1281,120000,1444444,1111,333333333,2222,44444,6666666,555555
35934936 35937087 - 2  1281,870      0,128
35934936 35937087 - 2  1281,870    0,1281

I think your previous code is working fine with this kind of problem. But if I'm trying to open the result in excel file the values are looking some thing like this in some parts. However the output looking fine in notepad or word pad. I dontknow the reason why.

7829885 7831552 + 1    1667               0
35934936 35937087 - 2  1,281,870       0,1,281120,000144,4444,11113333,33333,222244444,66666,66555555
35934936 35937087 - 2  1,281,870      0,128
35934936 35937087 - 2  1,281,870    0,1281

don't know why........

But i want the same values that i can see in word or notepad in excel. I tried but couldn't able to fugured out. Do you have any idea.