For every ID in column one, I want to get the min/max/total for each ID.
The values in different columns are not sorted, the actual attempt, works only if the columns are sorted.
input file
2010 1 44413 41105.0 21.75 146
2010 1 44415 41105.0 21.75 146
2010 1 44417 41105.0 21.75 100
2010 1 44419 41105.0 28.00 146
2010 1 50000 41105.0 21.75 200
2010 1 44423 41105.0 21.75 146
2011 1 44425 41105.0 21.75 146
2011 1 44427 41105.0 20.00 146
2011 1 70000 41105.0 21.75 146
2011 1 44433 41105.0 29.00 700
2011 1 44435 41105.0 21.00 146
2012 1 44437 41105.0 21.75 146
2012 1 20000 41105.0 21.75 150
2012 1 44441 41105.0 21.75 146
2012 1 90000 41105.0 21.75 146
2012 1 44445 41105.0 21.75 600
2012 1 44447 41105.0 21.75 146
2012 1 44447 41105.0 21.75 146
attempt
awk '{ currKey = $1 }
currKey != prevKey { prt(); min=$3;min1=$5;min2=$6;cnt=0}
{ prevRec=$0; prevKey=currKey; max=$3;max1=$10;max2=$6; cnt++ }
{ prevKey=currKey; TOTAL+=$6}
END { prt() }
function prt( f) {
if ( cnt ) {
split(prevRec,f)
print f[1],min,max,min1,max1,min2,max2,TOTAL, cnt
}
}' file | column -t
output from attempt
2010 44413 44423 21.75 21.75 146 146 884 6
2011 44425 44435 21.75 21.00 146 146 2668 5
2012 44437 44447 21.75 21.75 146 146 4002 7
output desired
2010 44413 50000 21.75 28.00 100 200 884 6
2011 44425 70000 20.00 29.00 146 700 1284 5
2012 20000 90000 21.75 21.75 146 600 1280 7
Appreciate your support