Here is one way using awk
:
$ awk '
BEGIN {
SUBSEP = FS;
print "col1 col2 col3 col4 col5"
}
FNR>1 {
a[$1,$2] = (a[$1,$2]?a[$1,$2]FS$5:$5)
}
END {
for(x in a) print x, a[x]
}' file1 file2 file3
col1 col2 col3 col4 col5
C 93 Aru Bui Cuu
A 91 Abu Bob Can
B 82 Anu Bag Con
You can pipe the output to sort
if you required sorted output. This does not limit to three files. It is scalable to n
number of files. Just add the file names at the end or use *
to glob to all files under a given directory.