Awk Doubt _ Urgent

Guys

I have the file TEST.csv generated after a join of two different files with the same columns:

key,string,data,number,key,string,data,number
abc,test,020202,3,abc,test,010305,4
abc,level,070202,9,abc,tool,010203,7
def,tool,010101,7,,,,
ghi,,,ghi,test,010203,8

I have to generate a new file from this file using the first columns $1,$2,$3,$4 however where is null it will automatically consider the other compensative column like: ghi,$2=$6

I tried to use the awk:

awk 'BEGIN { FS="," ; OFS="," ; key="" } {
if( key==$1 || key=="" ) {
if ($1="") print $1=$5;
if ($2="") print $2=$6;
if ($3="") print $3=$7;
if ($4="") print $4=$8;
}
key=$1;
}' TEST.csv | sort -t "," -k1,1b > NEW_FILE.csv

However the result is null...

Can you tell me what is the problem with my code and do you know any other way to do it?

Regards

i cant access unix so cant test this, but i think u can just write $1=$5 instead of
print $1=$5; and the print the first four after the inner block..

i dont quite understand the logic behind the line
if( key==$1 || key=="" ) {
and
key=$1;
but u wudve thot of smthing, anyway.. try it out

Or, and especially if this is a big file, import into a databse and use isnull

Hello Sir

The key=$1; is a variable that I set to make the if enter in the code making the relation witht the columns.

I�ve solved the problem witht the following code :

awk -F, 'BEGIN { FS="," ; OFS="," ; key="" } {
key=$1$8;
if( key==$1$8 || key=="" ) {
if ($22!="") $1=$22;
if ($23!="") $2=$23;
if ($24!="") $3=$24;
if ($25!="") $4=$25;
if ($26!="") $5=$26;
if ($27!="") $6=$27;
if ($28!="") $7=$28;
if ($29!="") $8=$29;
if ($41!="") $9=$41;
if ($30!="") $11=$30;
if ($31!="") $12=$31;
if ($32!="") $13=$32;
if ($34!="") $14=$34;
if ($38!="") $17=$38;
if ($39!="") $18=$39;
if ($40!="") $19=$40;
if ($43!="") $20=$43;
if ($42!="") $21=$42;
}
print $0}' key3.t | sort -t "," -k1,1b > key4.t

Thank you very much