From e9420bb7e26a5795fe651cf96158b773a6fe2339 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Thu, 5 Jan 2017 18:36:10 +1300 Subject: Add onl(1df) --- .gitignore | 1 + Makefile | 1 + README.markdown | 1 + bin/onl.awk | 28 ++++++++++++++++++++++++++++ man/man1/onl.1df | 18 ++++++++++++++++++ 5 files changed, 49 insertions(+) create mode 100644 bin/onl.awk create mode 100644 man/man1/onl.1df diff --git a/.gitignore b/.gitignore index bcefffcb..a3a6404f 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ bin/med bin/mftl bin/min bin/mode +bin/onl bin/rfct bin/rndi bin/sd2u diff --git a/Makefile b/Makefile index a974c7b1..38694d31 100644 --- a/Makefile +++ b/Makefile @@ -79,6 +79,7 @@ BINS = bin/csmw \ bin/mftl \ bin/min \ bin/mode \ + bin/onl \ bin/rfct \ bin/rndi \ bin/sd2u \ diff --git a/README.markdown b/README.markdown index 707e80cd..2767e04e 100644 --- a/README.markdown +++ b/README.markdown @@ -475,6 +475,7 @@ Installed by the `install-bin` target: * `mkcp(1df)` creates a directory and copies preceding arguments into it. * `mkmv(1df)` creates a directory and moves preceding arguments into it. * `motd(1df)` shows the system MOTD. +* `onl(1df)` crunches input down to one printable line. * `pa(1df)` prints its arguments, one per line. * `paz(1df)` print its arguments terminated by NULL chars. * `pit(1df)` runs its input through a pager if its standard output looks like 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" } diff --git a/man/man1/onl.1df b/man/man1/onl.1df new file mode 100644 index 00000000..7e84b9ba --- /dev/null +++ b/man/man1/onl.1df @@ -0,0 +1,18 @@ +.TH ONL 1df "January 2017" "Manual page for onl" +.SH NAME +.B onl +\- force standard input onto one printable line +.SH USAGE +.B onl +FILE1 [FILE2 ...] +.br +.B onl +< FILE +.br +program | +.B onl +.SH DESCRIPTION +Condense input down to one line with only printable characters, no leading or +trailing spaces, and a single space in place of multiple spaces or tabs. +.SH AUTHOR +Tom Ryder -- cgit v1.2.3