replacing characters with awk

Hi there!

I'm new in this and probably is a quite simple task but I still cannot manage to do it:

I have to read some files line by line and then change the input format into another one, but the very first step is to replace the empty variables by error values. I mean, each line looks like:

123.45,rank,bla1,,wwer334,464,2234l20,,,,,

  1      2     3  4       5        6       7     8 9 10 11 12

(the first line is the 'actual' input line while the other one indicates the column# or variable# )

the output should be like:

123.45,rank,bla1,-9999,wwer334,464,2234l20,-9999,-9999,-9999,-9999,-9999

  1      2     3       4         5          6       7          8        9        10      11       12

Well, this is what I have written to try to do it (I forgot telling, my scripts are in bash):

#!/bin/sh
#--------------
cat input | awk -F ',' ' function fillit(num) {if (num != "") print num; else print -9999} {print "$1="$1,"$2="$2,"$3="$3,"$4="fillit($4),"$5="$5,"$6="$6,"$7="$7,"$8="fillit($8),"$9="fillit($9),"$10="fillit($10),"$11="fillit($11),"$12="fillit($12)} '
#
#--------------

I defined a function called fillit() that subsitutes a blank variable by an error value. And the " " commentaries before each variable are just to help me knowing what was going on...

The problem is that the output looks like:

-9999
-9999
-9999
-9999
-9999
-9999
$1=123.45 $2=rank $3=bla1 $4= $5=wwer334 $6=464 $7=2234l20 $8= $9= $10= $11= $12=

While I was expecting something like:

$1=123.45 $2=rank $3=bla1 $4=-9999 $5=wwer334 $6=464 $7=2234l20 $8=-9999 $9=-9999 $10=-9999 $11=-9999 $12=-9999

That is, it actually substitutes the variables, but instead of putting them in the propper order, it puts them in a column at the beginning .

Well, thank you very much in advance for your help ;�).

echo '123.45,rank,bla1,,wwer334,464,2234l20,,,,,' | nawk -F, '{for(i=1;i<=NF;i++) if ($i == "") $i="-9999"}1' OFS=','

Wow,

Thanks a lot! It really helped me!