for aa in a b; do cat $aa |sed -e "s/ / $aa /;"; done |\
sed -e "s/\([^ ]*\).*/& \1/;" |sort -r |uniq -3 |cut -d" " -f 1,3