#! /bin/sh USAGE=' ################################################################################ # NAME # @(#) add up numbers in a specified column of file(s) or stdin # SYNOPSIS # addup [column] [files] # DESCRIPTION # This command will read its files (or standard input) and sum the # numbers in the specified column. If column is omitted, # the first column is added. # # RETURN VALUE # 0 Successful completion # 1 Error condition occurred ################################################################################ ' ################################################################################ colnum=${1:-1} case "$colnum" in [1-9]*) colnum="$1"; shift;; *) echo "E-R-R-O-R: first argument ($1) is not numeric." 1>&2 echo "$USAGE" 1>&2 exit 1 esac #expr "$colnum" + 1 >/dev/null 2>&1 awk "{sum += \$$colnum} END{print sum}" ${1+"$@"} ################################################################################ exit ################################################################################