#!/usr/bin/awk BEGIN{ FS = "\t" } { tab1[NR] = $1; tab2[NR] = $2; } END{ commun = 0; diff = 0; for (i = 1; 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 "diff" diff ++; } #print i, tab1[i], tab2[i], "-", j, tab1[j], tab2[j] } print (commun + diff) / (NR * (NR - 1) / 2) }