21 lines
377 B
Bash
Executable File
21 lines
377 B
Bash
Executable File
#!/bin/sh
|
|
|
|
COLUMN="1"
|
|
FORMAT="TOTAL: %s\n"
|
|
|
|
if [ "$1" = "-h" ]; then
|
|
cat<<EOF
|
|
Usage: ${0##*/} [COLUMN] [FORMAT]
|
|
|
|
Sum COLUMN (default to column $COLUMN) and output result with format FORMAT
|
|
(default to $FORMAT).
|
|
|
|
EOF
|
|
exit
|
|
fi
|
|
|
|
[ $# -ge 1 ] && COLUMN="$1" && shift
|
|
[ $# -ge 1 ] && FORMAT="$1"
|
|
|
|
awk -v format="$FORMAT" '{total += $'"$COLUMN"'; print} END {printf format, total}'
|