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