bash script range calculations

Hi,

I have data in the following form:

AB001 10
AB002 9
AB003 9
etc
AB200 5

What I need to do is sum up the second value according to groups of the first, i.e. AB001 to AB030 the total being X, AB031 to AB050 the total being Y etc (there are 5 AB ranges of different sizes). I'm sure it should be fairly straight forward awk one liner, but am just having a mental block trying to work it out!

Anyone?

Could this help you ?

awk 'BEGIN{g1=30;g2=50;g3=70;g4=90;g5=100}
{if(NR<=g1){gr1_total+=$2}
if(NR>g1&&NR<=g2){gr2_total+=$2}
if(NR>g2&&NR<=g3){gr3_total+=$2}
if(NR>g3&&NR<=g4){gr4_total+=$2}
if(NR>g4&&NR<=g5){gr5_total+=$2}
}
END {
print "GROUP 1:- "gr1_total
print "GROUP 2:- "gr2_total
print "GROUP 3:- "gr3_total
print "GROUP 4:- "gr4_total
print "GROUP 5:- "gr5_total
}' infile
# range of 5
  nawk '{gsub("[^0-9]","",$1);a[int($1/r)]+=$2}END{for(i in a) print "Range " i ":",a}' r=5 myFile | sort -k1.1
#range of 20
  nawk '{gsub("[^0-9]","",$1);a[int($1/r)]+=$2}END{for(i in a) print "Range " i ":",a}' r=20  myFile | sort -k1.1

Thanks both of you for the replies - I've used Pravin27's suggestion and works perfectly!