commit 0bbb647213314c0ff6977636a70422ecbd249a49
parent 2425c59685bd3283e23b6e028425614a3d573945
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date: Sat, 28 Aug 2021 13:36:41 -0700
Add wc(1) wrapper to give percentage of total counts
Diffstat:
1 file changed, 27 insertions(+), 0 deletions(-)
diff --git a/local/bin/.local/bin/wcp b/local/bin/.local/bin/wcp
@@ -0,0 +1,27 @@
+#!/bin/sh
+# Copyright 2021 Jacob R. Edwards
+# License: GPLv3
+# wcp -- word count percent
+
+wc -- "$@" | awk '{
+ ++len;
+ entries[len,1] = $1
+ entries[len,2] = $2
+ entries[len,3] = $3
+ sub("^ +[0-9]+ +[0-9]+ +[0-9]+ ", "", $0);
+ entries[len,4] = $0;
+}
+END {
+ if (entries[len,4] != "total") {
+ print("Missing total") > "/dev/stderr";
+ exit 1;
+ }
+ for (i = 1; i < len; ++i) {
+ for (j = 1; j <= 3; ++j) {
+ printf("%4.1f ",
+ (entries[len,j] ? (entries[i,j] / entries[len,j]) : 0) * 100);
+
+ }
+ print(entries[i,4]);
+ }
+}'