awk '
BEGIN {
print "TABLE,REF-IO,HEAD-IO,DIFF-IO,REF-SELECT,HEAD-SELECT,DIFF-SELECT"
OFS = ", "
}
FNR==NR {
A[$1]=$2
B[$1]=$3
next
}
{
if (!($1 in A)) {
A[$1] = B[$1] = 0
}
diff_io = $2 - A[$1]
diff_sel= $3 - B[$1]
C[$1] = 1
}
diff_io || diff_sel {
if (first) {
print line
}
first = 1
line = $1 OFS $2 OFS A[$1] OFS diff_io OFS $3 OFS B[$1] OFS diff_sel
}
END {
for (name in A) {
if (!(name in C)) {
print name, 0, A[name], -A[name], 0, B[name], -B[name]
}
}
print line
}
' head_file ref_file
Para digitar rapidamente, você pode executar a tarefa via join
:
join -a1 -a2 -e0 <(sort head_file) <(sort ref_file) -o0,1.2,2.2,0,1.3,2.3 |
awk '
BEGIN {
print "TABLE,REF-IO,HEAD-IO,DIFF-IO,REF-SELECT,HEAD-SELECT,DIFF-SELECT"
OFS = ", "
}
{
$4=$2-$3
$7=$5-$6
}
/Total/ {
end=$0
next
}
$4!=0 || $7!=0;
END {
print end
}'