modify and use awk sed program

The following awk script creates a file b.dat.

awk '{print substr($0,1,27),substr($2,index($2,"_")+1)," ",substr($0,49)}' a.dat > b.dat

I need this script to be modified to also sum $3 values by distinct $1 and $2
fields.

Current file

W2_2009275 2    8 
W2_2009275 2    7 
W1_2009275 1   5 
W1_2009275 1   4 

New file

W2_2009275 2 15 
W1_2009275 1 9

Try:

awk '{d1=substr($0,1,27);d2=substr($2,index($2,"_")+1);d3=substr($0,49)+0;a[d1" "d2]=(a[d1" "d2]+0)+d3}END{for(i in a)print i,a}' a.dat > b.dat

It works now. Thank you.

Another one:

awk '{a[$1" "$2]+=$3}END{for(i in a){print i,a}} 'file

Regards