BEGIN {FS=","; srand() } NR==1 { for(I=1;I<=NF;I++) Names[I]=$I; next} { for(I=1;I<=NF;I++) { N++; if (++All[I,$I] == 1 ) Unique[I,++Unique[I,0]] = $I }} END { for(I in Names) sortCol(N,I,All,Unique,Cdf); saya("Cdf",Cdf); } function sortCol(n,i,all,unique,cdf,\ max,j,k,ls,l,m,l2k,values) { printf " i " i; max=unique[i,0]; for(j=1;j<=max;j++) { k = unique[i,j]; l = all[i,k] + rand()/1000; printf " l " l ls += l; l2k[l] = k; } max=asorti(l2k,values); printf " max " max for(j=max;j>=1;j--) { k = l2k[values[j]]; print " j " j " k " k " ls " ls " k/ls " k/ls cdf[i,++cdf[i,0]]=k/ls; }} function saya(s,a,q1,q2,eol, com,i,j,n,tmp,str,sep) { com="sort"; q1= q1 ? "\"" : ""; q2= q2 ? "\"" : ""; for(i in a) { sep=""; str= s"["; n=split(i,tmp,SUBSEP); for(j=1;j<=n;j++) { str=str sep q1 tmp[j] q1; sep=","; } print str "] = " q2 a[i] q2 eol | com; }; close(com); }