awk triple files input

I have 3 files, as below:

File1:

5372,5372,0,0,,1,0,1,1,0,1,0,0,0,0,0,0,1107,1107,,1.620000,1,2015-08-12
2110,2110,0,0,,0,0,1,0,0,0,0,1,1,1,1,1,1601,1601,,9.500000,1,2015-05-29
6900,6900,0,0,,1,0,1,1,0,0,0,0,0,0,0,0,1107,1107,,1.369000,1,2025-09-23
8755,8755,0,0,,1,0,1,1,0,0,0,0,0,0,0,0,1107,1107,,3.232000,1,2025-05-22

File2:

5372,4074,,,,,2,,,
2110,4100,,,,,0,,,
6900,5246,,,,,0,,,
8755,5270,,,,,0,,,

File3:

2187,2500
2188,1500
4227,2000
5270,3000

Noting that the NF for File1, File2 and File3 respectively is 47, 10 and 2

The needs is to check if the $23 from File1 is equal to 2025, if yes, then convert $21 to $21*1000, then save the $1 in an array.
After that, get $2 from File2 for $1 that we got from File1.

Now we should compare $21 from File1 with $2 from File3 if the value greater than or equal, print $1 from File1.

The expected output for above files:
8755

I have tried the following code:

awk -F"," '{if(NF==47){if($23 ~ /2025/){$21=$21*1000}{A[$1]=$0}}else{if(NF==10){if(A[$1]==$0){B[$1]=$0}}{if(NF==2){B[$1]==$0 && $23>=$2}{print $0}}}'

but the outputs always were File3

Please Advise.


Source: linux

Leave a Reply