summaryrefslogtreecommitdiff
path: root/tabize
diff options
context:
space:
mode:
authorPeter Wu <lekensteyn@gmail.com>2013-04-23 18:59:15 +0200
committerPeter Wu <lekensteyn@gmail.com>2013-04-23 18:59:15 +0200
commitaf38cb02a9ca95b20056bc92e73fe72a45d1f523 (patch)
tree41628cac3a02d2c4dcf4ff6ecbb1fb8c5378db20 /tabize
downloadscripts-af38cb02a9ca95b20056bc92e73fe72a45d1f523.tar.gz
Initial checkin.
Diffstat (limited to 'tabize')
-rwxr-xr-xtabize30
1 files changed, 30 insertions, 0 deletions
diff --git a/tabize b/tabize
new file mode 100755
index 0000000..467581a
--- /dev/null
+++ b/tabize
@@ -0,0 +1,30 @@
+#!/bin/sh
+# Input: space-separated
+column -t \
+| sed 's/ */&| /g' \
+| tac | awk 'BEGIN {
+ s="";
+ line="";
+}
+{
+ if (line) print line;
+ if (s == "") {
+ split($0, chars, "");
+ for (i=1; i<=length(chars); i++) {
+ if (chars[i] == "|")
+ s=s "+";
+ else
+ s=s "-";
+ }
+ } else {
+ while (length(s) < length($0)) {
+ s = s "-";
+ }
+ }
+ line = $0;
+}
+END {
+ print s;
+ s="";
+ print line;
+}' | tac