From fd0203ff3ad2de81bd828eda809a89f8be7458d6 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Thu, 5 Jan 2017 19:05:46 +1300 Subject: Adopt much simpler approach for onl(1df) --- bin/onl.awk | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) (limited to 'bin') diff --git a/bin/onl.awk b/bin/onl.awk index 140fb64c..c12039db 100644 --- a/bin/onl.awk +++ b/bin/onl.awk @@ -1,27 +1,14 @@ # Flatten input into one single-space separated line with no unprintable chars -# For each not-all-spaces line: +# For each line of input ... { - # Strip unprintable chars - gsub(/[^[:print:]]/, "") + # Strip out non-printable characters and rebuild the fields + 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 each field, without a newline; add a leading space if it's not the + # very first one + for (i = 1; i <= NF; i++) + printf (f++) ? " %s" : "%s", $i } # Print a newline to close the line -- cgit v1.2.3