Output format - comparison with I/p file

Hi,

I have a file which contains more than 1 lakh records like following:

a. name, id, city, state, country, phone (Expected I/P file format)
name, id, city,, state, country, phone (Current I/P file format )

I want to achieve following tasks,

a, Remove the extra comma in the City field.
b, Add / Remove extra string in the id field (eg. if id is 5001 I want to add 0 in the beginning, ie, 05001 / in some case, if id is 0123 remove 0 from the beginning ie, 123.

Please advice.

Thanks and Regards,
Vel

Case 1 : For removing multiple comma's which are together.

sed '1,$s/,,/,/' sourcefile >> targetfile

Case 2 : I understand like this.
If the id is starting with '0' then eliminate it
If its not starting with '0' then add it.

The scenario is pretty tricky...
Lets say we have a file like this
cat test
1001,aa,bb,cc,dd
1001,aa,bb,cc,dd
1001,aa,bb,cc,dd
1001,aa,bb,cc,dd
011,aa,bb,cc,dd
011,aa,bb,cc,dd
011,aa,bb,cc,dd
011,aa,bb,cc,dd
aa,bb,cc,dd
aa,bb,cc,dd
aa,bb,cc,dd
aa,bb,cc,dd
aa,bb,c,d

and if i run like this
sed '1,$s/^[1-9]/0/;1,$s/^0//' test

Check the output..

001,aa,bb,cc,dd
001,aa,bb,cc,dd
001,aa,bb,cc,dd
001,aa,bb,cc,dd
11,aa,bb,cc,dd
11,aa,bb,cc,dd
11,aa,bb,cc,dd
11,aa,bb,cc,dd
aa,bb,cc,dd
aa,bb,cc,dd
aa,bb,cc,dd
aa,bb,cc,dd
aa,bb,c,d

but we didnt need this..
We will have to distinguish between them..
so use this command.
sed '1,$s/^[1-9]/-0&/;1,$s/^0//' test >> test1
cat test1
output

-01001,aa,bb,cc,dd
-01001,aa,bb,cc,dd
-01001,aa,bb,cc,dd
-01001,aa,bb,cc,dd
11,aa,bb,cc,dd
11,aa,bb,cc,dd
11,aa,bb,cc,dd
11,aa,bb,cc,dd
aa,bb,cc,,dd
aa,bb,cc,,dd
aa,bb,cc,,dd
aa,bb,cc,,dd
aa,bb,c,d

Now u just have to eliminate the "-"
sed 's/^-//g' test1 >> test2
cat test2
output

01001,aa,bb,cc,dd
01001,aa,bb,cc,dd
01001,aa,bb,cc,dd
01001,aa,bb,cc,dd
11,aa,bb,cc,dd
11,aa,bb,cc,dd
11,aa,bb,cc,dd
11,aa,bb,cc,dd
aa,bb,cc,dd
aa,bb,cc,dd
aa,bb,cc,dd
aa,bb,cc,dd
aa,bb,c,d

Hope i have made this clear.
Let me know if any.....