Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# Take output from iwinfo "$INTERFACE" scan command
# ... combine each stanza (record) into a single line and
# prefix with hostname
# Call with -v h="$HOSTNAME"
BEGIN {h=sprintf("%s:\t", h); line=h};
/^[^ ]/ {print line; line=h};
/^ / {line=sprintf("%s %s", line, $0)};
END {print line}
# Explanation:
## mini-state machine parser: prefix set by -v command line arg; then formatted;
## any line starting with non-space dumps previous state and starts new state with just prefix
## any other line (starts with a space) adds to current (line) state
## dump final state (line) at END
# "extra" semicolons on line endings allow cut-n-paste direct to command line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment