BEGIN{ FS=OFS="\t" } FNR==NR{ if(!a[$2]){ a[$2]=$1 }else{ a[$2]=a[$2]";"$1 } } FNR!=NR{ if(a[$1] && a[$2]){ split(a[$1],g1,";") split(a[$2],g2,";") for(i1 in g1){ for(i2 in g2){ if(g1[i1] != g2[i2]){ print g1[i1],g2[i2],$3,$4,$5,$6,$7,$8,$9,$10 } } } } }