aboutsummaryrefslogtreecommitdiff
path: root/bin/onl.awk
blob: 140fb64c67a8bf850b9f1dfd0502f4a0f2425672 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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" }