aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-01-05 18:36:10 +1300
committerTom Ryder <tom@sanctum.geek.nz>2017-01-05 18:36:10 +1300
commite9420bb7e26a5795fe651cf96158b773a6fe2339 (patch)
tree0e0e036d501a90c4381118f633f32c29209d67d0 /bin
parentAdd htenc(1df) and htdec(1df) (diff)
downloaddotfiles-e9420bb7e26a5795fe651cf96158b773a6fe2339.tar.gz
dotfiles-e9420bb7e26a5795fe651cf96158b773a6fe2339.zip
Add onl(1df)
Diffstat (limited to 'bin')
-rw-r--r--bin/onl.awk28
1 files changed, 28 insertions, 0 deletions
diff --git a/bin/onl.awk b/bin/onl.awk
new file mode 100644
index 00000000..140fb64c
--- /dev/null
+++ b/bin/onl.awk
@@ -0,0 +1,28 @@
+# Flatten input into one single-space separated line with no unprintable chars
+
+# For each not-all-spaces line:
+{
+ # Strip unprintable chars
+ gsub(/[^[:print:]]/, "")
+
+ # All horizontal whitespace groups to one space
+ gsub(/[ \t]+/, " ")
+
+ # No leading or trailing space
+ sub(/^ /, "")
+ sub(/ $/, "")
+
+ # If there's nothing left, go on to the next line
+ if (!length)
+ next
+
+ # If this isn't the first line, add a leading space
+ if (NR > 1)
+ printf " "
+
+ # Print the content without a newline
+ printf "%s", $0
+}
+
+# Print a newline to close the line
+END { printf "\n" }