awk '/Tom/{for(i=1;i<=NF;i++)if($i=="Tom")s+=$(i+1);print "Tom",s;s=0}'
Tom 100 John 10 Tom 100
Tom 200
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!