commit d86802e864b39342cdecab6f0a22d2086ea4b9fe
parent 139a939b56d59c34b315439ecb038ba71ad28baf
Author: gearsix <gearsix@tuta.io>
Date:   Fri, 29 Mar 2024 15:12:54 +0000
added awkcol
Diffstat:
2 files changed, 25 insertions(+), 0 deletions(-)
diff --git a/README.md b/README.md
@@ -101,6 +101,7 @@ Scripts related to string parsing/manipulation
 - *pomodoro* - a [pomodoro](https://en.wikipedia.org/wiki/Pomodoro_Technique) timer.
 - *while-true* - clear the terminal, run $1 sleep ($2 || 1 sec), repeat forever (Ctrl+C to cancel).
 - *onfilech* - stat a file ($1) every 10 seconds, if the output changes, run a command ($2...$n).
+- *awkcol* - column with awk (at one point  column wasn't available but awk was)
 
 **depreciated**
 
diff --git a/src/posix/awkcol.sh b/src/posix/awkcol.sh
@@ -0,0 +1,24 @@
+#!/usr/bin/env sh
+# columnate with awk
+# description: sometimes you reach the limit of 'column'
+# dependencies: awk 
+# e.g.$ mount | awkcol
+# source: http://awk.freeshell.org/Columnate
+awk '{
+    line[NR] = $0    # saves the line
+    for (f=1; f<=NF; f++) {
+        len = length($f)
+        if (len>max[f])
+            max[f] = len    # an array of maximum field widths
+    }
+}
+
+END {
+    for(nr=1; nr<=NR; nr++) {
+        nf = split(line[nr], fields)
+        for (f=1; f<nf; f++)
+            printf "%-*s", max[f]+2, fields[f]
+        print fields[f]     # the last field need not be padded
+    }
+}'
+