#!/usr/bin/awk { tab1[$1] = $2; tab2[$1] = $4; } END{ NR -= 2; commun = 0; diff = 0; for (i = 0; i < NR; i ++) for (j = i + 1; j < NR; j ++){ if (tab1[i] == tab1[j] && tab2[i] == tab2[j]){ #print "commun" commun ++; } if (tab1[i] != tab1[j] && tab2[i] != tab2[j]){ #print "commun" diff ++; } #print i, tab1[i], tab2[i], "-", j, tab1[j], tab2[j] } print commun + diff; }