Works great!

I recommend making a modification to to enclose $KEY in quotes in the line containing

RESULT=`grep -c $KEY $TMP`

so that multiple word keys separated by spaces can be used.