Scripts: colsum sums the specified column
parent
cb030e8710
commit
1471942ed1
|
@ -0,0 +1,20 @@
|
|||
#!/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}'
|
Loading…
Reference in New Issue