#!/bin/bash
#===============================================================================
#
#          FILE: avg
#
#         USAGE: avg
#
#   DESCRIPTION: Print summed value from the Standard Input
#
#          BUGS:  ---
#        AUTHOR: rickz (Rick Zhang), xlrickz@gmail.com
#       COMPANY: X-LEGEND Entertainment Corp.
#       CREATED: Wed May  2 13:05:28 KST 2012
#      REVISION: 1.0
#
#          TODO:
#
#===============================================================================

#set -o nounset                              # Treat unset variables as an error
#set -m                                      # Enable job control

TOTAL="$(
	for number in $(cat | grep "[0-9]");do
		echo $number
	done \
	| tr '\n' '+'
)0"

COUNT="$(($(tr '+' '\n' <<< $TOTAL | wc -l)-1))"

echo "scale=3 ; ($TOTAL)/$COUNT" | bc -l
