Use the following awk line to do this:
r.stats -c <dem_layer> | awk 'BEGIN{countcells=0; adddems=0}\
{countcells += $2; adddems += $1*$2}\
END{print "The average is:",adddems/countcells}'
You may modify it if you wish.
Nalneesh Gaur, River Forecast Center, TULSA