# example - gawk -f avgcolumn.awk I=8 attr.out BEGIN { FS=OFS="," Sum=0; I=12; } { #Subset=$12 Subset=$I for(J=1; J<=15; J++) { target="-"J"-"; if (index(Subset, target)!=0) { Count[J]++; Sum++; } } } END { print Sum/NR }