Handling 3 Files using awk
That worked for me:
awk -F, 'FNR==1{++f} \
f==1 && $2==7 {a1[$1]++; a2[$2]=$3; o=$0} \
f==2 && a1[$1] {o=o","$3","$4; a3[$3]=$4} \
f==3 && a3[$1] && $2==a3[$1] && a2[$3] && $4<a2[$3] {print o}' \
file1 file2 file3
Explanation:
- The first line (
FNR==1{++f}
) increments the file index to later determine in which file we are 1-3. - file1: if
$2
equals7
- fill an array
a1
with$1
as index anda2
with$2
as index and$3
as value - write down the
o
variable (output) with the first 3 fields
- fill an array
- file2: if
$1
offile2
equals$1
offile1
(prevously written ina1
)- append
$3
and$4
to the output variableo
. - fill an array
a3
with$3
as index and$4
as value.
- append
- file3: if:
$1
equals file2s$3
(index ofa3
)$2
equals file2s$4
(value ofa3
)$3
equals file1s$2
(index ofa2
)$4
is lower than file1s$3
(value ofa2
)
- then:
- print the value of
o
.
- print the value of