config

OpenBSD system configuration
git clone git://jacobedwards.org/config
Log | Files | Refs | README

commit 823a5e4e7d69b5f93b57c21eff6a3db8e5558924
parent 9c17fecc04ba5928d751f9a9f3fe27c9c9f06bba
Author: Jacob R. Edwards <n/a>
Date:   Mon, 28 Nov 2022 21:47:15 -0600

Add the total script

This script does as you would expect; it totals numeric input from
the standard input. Not only will this save typing the awk script
every time for this somewhat commonly used operation, it has the
ability to work with binary prefixes (KiB, MiB, etc.) which I believe
could be very useful.

Diffstat:
Alocal/bin/bin/total | 14++++++++++++++
1 file changed, 14 insertions(+), 0 deletions(-)

diff --git a/local/bin/bin/total b/local/bin/bin/total @@ -0,0 +1,14 @@ +#!/bin/sh +# Copyright 2022 Jacob R. Edwards +# Total numeric input (with the -b flag it interpretes binary +# prefixed values, e.g. 352K, 23M, etc.) + +total() awk '{ t += $1 } END { print t }' + +case "$#$1" in +(0) total ;; +(1-b) human.awk undo | total | human.awk ;; +(*) + echo 'usage: total [-b]' 1>&2 + exit 1 +esac