BEGIN{ FS=OFS="\t" } { a[$1"\t"$2"\t"$3]=$0 if(!pair[$1"\t"$2] || pair[$1"\t"$2] < $3){ pair[$1"\t"$2]=$3 } } END{ for(i in pair){ split(i,g,"\t") if(!pair[g[2]"\t"g[1]]){ print a[i"\t"pair[i]] }else if(pair[g[2]"\t"g[1]] == pair[g[1]"\t"g[2]]){ print a[i"\t"pair[i]] delete pair[g[2]"\t"g[1]] }else if(pair[g[2]"\t"g[1]] < pair[g[1]"\t"g[2]]){ print a[i"\t"pair[i]] } } }