Does default awk field splitting collapse multiple spaces the same way split() does?
0 reputation · 24 Oct 2022, 12:32 UTC
I am writing an awk alert script that parses whitespace-delimited log lines and fires when a numeric field crosses a threshold. The script must avoid notification noise caused by empty or misaligned fields.
POSIX awk treats a lone space in FS specially: it collapses runs of whitespace and ignores leading and trailing spaces when splitting input records. In contrast, split(string, array, " ") splits on every individual space character, so consecutive spaces can produce empty elements. Missing or uninitialized fields evaluate as empty strings in arithmetic and relational tests, which may silently suppress or trigger threshold alerts across gawk, mawk, and nawk.
Does split($0, fields, " ") reproduce default field splitting when fields are separated by multiple spaces? Will empty fields from consecutive delimiters be treated as zero in numeric threshold comparisons? Should the alert logic rely on default FS splitting or explicitly normalize whitespace before splitting?