2014-03-06 15:21:53 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
COLUMN="1"
|
|
|
|
FORMAT="TOTAL: %s\n"
|
|
|
|
|
|
|
|
if [ "$1" = "-h" ]; then
|
2014-11-12 16:15:39 +01:00
|
|
|
cat<<EOF
|
2014-03-06 15:21:53 +01:00
|
|
|
Usage: ${0##*/} [COLUMN] [FORMAT]
|
|
|
|
|
|
|
|
Sum COLUMN (default to column $COLUMN) and output result with format FORMAT
|
|
|
|
(default to $FORMAT).
|
|
|
|
|
|
|
|
EOF
|
2014-11-12 16:15:39 +01:00
|
|
|
exit
|
2014-03-06 15:21:53 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
[ $# -ge 1 ] && COLUMN="$1" && shift
|
|
|
|
[ $# -ge 1 ] && FORMAT="$1"
|
|
|
|
|
|
|
|
awk -v format="$FORMAT" '{total += $'$COLUMN'; print} END {printf format, total}'
|