#! /usr/bin/env bash # # Usage: average # ex: average Total ./myFile # grep -e "$1" "$2" | awk -v what="$1" -F: ' BEGIN {sum = 0; count = 0; units = ""} { split($2, parts, " "); sum += parts[1]+0; count++; if (units == "") { units = parts[2]; } } END {print what " (av):", sum/count, units} '