#!/usr/bin/gawk -f BEGIN{ FS=","; MAX=-10**32; MIN=10**32; min=0; max=0; } /@attribute/ { Attr++} /@data/ { Start=1 } Pass==1 && Start && NF>1{ if(!($Attr in Seen)) { Seen[$Attr]=1; } else { Seen[$Attr]++; } } Pass==1 && Start && NF>1{ MAX=-10**32 MIN=10**32 for(i in Seen) { # note down the attribue not the number of isntances if(MAX= Seen[i]) { MIN=Seen[i] min=i; #print MIN "\t" i } } } Pass==2 && $NF!=max{ #print $0 } Pass==2 && $NF==max && ij<(int(0.75*MAX)){ #print $0 ij++; } END{ print MIN "\t" MAX }