#!/usr/bin/gawk -f BEGIN { FS = OFS = ","; } NR==1{ MinCost=MaxCost=$1; MinAtt=MaxAtt=$2; k = 0; } { k++; Cost[k] = $1; Att[k] = $2; if (MinCost > $1) MinCost = $1; if (MaxCost < $1) MaxCost = $1; if (MinAtt > $2) MinAtt = $2; if (MaxAtt < $2) MaxAtt = $2; } END { Bins = int(k/10); interval = (MaxAtt - MinAtt)/Bins; for (i = 1; i<=Bins; i++) { MinCostArray[i] = 10^20; MaxCostArray[i] = -10^20; } for (i=1; i<=k; i++) { place = int ((Att[i] - MinAtt)/interval); if (MinCostArray[place] > Cost[i]) MinCostArray[place] = Cost[i]; if (MaxCostArray[place] < Cost[i]) MaxCostArray[place] = Cost[i]; } for (i = 1; i<=Bins; i++) { if (MinCostArray[i] != 10^20 && MaxCostArray[i] != 10^20) { print MinCostArray[i], MinAtt + i*interval; print MaxCostArray[i], MinAtt + i*interval; } } }