Consider following files:
file1:
boo,8,1024
foo,7,2048
file2:
foo,0,24,154
noo,0,10,561
file3:
24,154,7,1024,0
What I need is to go to File1 and check if $2==7; if true, take $1, $2 and $3 from File1; now I have to compare if $1 from File1 equal to $1 from File2; if true, I have to take $3 and $4 from File2 which not exist in File1, then I have to go to File3 and check if $1 from File3 is equal to $3 from File2, and $2 from File3 is equal to $4 from File2; if yes, then I have to check if $2 from File1 is equal to $3 from File3, then if this condition is true, I have to compare $3 from File1 with $4 from File3, if $3 from File1 is more than $4 from File3.
I tried the following script:
cat [file1] [file2] [file3] |
awk -F,
'{if(NF==3)
{if($2==7){a[$1]=$1; b[$1]=$2; c[$1]=$3}
}else
{if(NF==4){if(a[$1]==$1){d[$3]=$3; e[$4]=$4}
}else
{if(NF==5){if(d[$1]==$1 && e[$2]==$2){print a[$1], b[$1], c[$1], d[$1]}}
}
}
}'
The desired output is:
foo,7,2048,24,154,1024