Skip to content

Instantly share code, notes, and snippets.

@JimDennis
Created March 9, 2019 21:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JimDennis/812280af4afc8f54d03ddf3e9b68a371 to your computer and use it in GitHub Desktop.
Save JimDennis/812280af4afc8f54d03ddf3e9b68a371 to your computer and use it in GitHub Desktop.
# 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