#! /bin/bash Data=$1 Method=$2 grep -v "#" $Data | gawk -v col=$Method 'BEGIN{FS=OFS=","}{if($col!="key"&&$col!="Method"){name[$col]++}}END{for (x in name){print x}}' > names.tmp NumMethods=$(gawk 'END{print NR}' names.tmp) for ((i=1;i<=$NumMethods;i++)) do name=$(gawk -v i=$i 'NR==i{print $0}' names.tmp) echo -n $name"," gawk -v name=$name -v col=$Method 'BEGIN{FS=OFS=","}$col==name{print $0}' $Data | gawk 'END{print NR}' done rm names.tmp