awk -F\| '
NR==FNR { a[$1] = $2; next }
a[$1]!=$NF {
printf "%s, %s Cnt:%d %s Cnt:%d\n", $1, ARGV[1], a[$1], ARGV[2], $NF
}
{ delete a[$1] }
END {
for (i in a) {
printf "%s, %s Cnt:%d %s Cnt:%d\n", i, ARGV[1], a[i], ARGV[2], 0
}
}' file1 file2 | sort -k1
Output:
2014-04-23, file1 Cnt:5484572 file2 Cnt:0
2014-04-24, file1 Cnt:2822096 file2 Cnt:0
2014-04-27, file1 Cnt:0 file2 Cnt:2667066
2014-04-28, file1 Cnt:2667066 file2 Cnt:7746836
2014-04-30, file1 Cnt:0 file2 Cnt:2822060
It removes elements of the array that match file2
, then prints all remaining elements of the array. This does not save the order of lines, so I have piped it to sort -k1
.