awk — Regex Traps

awk uses ERE — no \d, no lookaheads, no \b
echo '2026-04-11 port 443 open' | \
  awk '/[0-9]+/'
# CORRECT — POSIX range; \d is PCRE and silent-fails in awk
POSIX character classes in awk
cat <<'EOF' > /tmp/demo.txt
VLAN10 data 10.50.1.0/24
vlan20 voice 10.50.2.0/24
*** separator ***
VLAN99 quarantine 10.50.99.0/24
EOF

# Digits only
awk '/[[:digit:]]+/' /tmp/demo.txt

# Alphabetic only (skips *** line)
awk '/^[[:alpha:]]/' /tmp/demo.txt

# Alphanumeric start (skips *** line)
awk '/^[[:alnum:]]/' /tmp/demo.txt
Range pattern closes immediately when start matches stop
# WRONG — SEE ALSO starts with S, matches ^[A-Z], range opens and closes same line
man awk | col -b | awk '/^SEE ALSO/,/^[A-Z]/'

# CORRECT — state machine with next prevents same-line close
man awk | col -b | awk '/^SEE ALSO/{p=1; next} /^[A-Z]/ && p{exit} p'
man pages contain invisible escape codes — always col -b first
# WRONG — backspace formatting breaks pattern matching
man grep | awk '/^EXAMPLES/{p=1} p'

# CORRECT — strip formatting
man grep | col -b | awk '/^EXAMPLES/{p=1} p'
printf does NOT add newline — print does
echo '10.50.1.20 ise-01 443' | awk '{print $1}'
# Output: 10.50.1.20\n (newline automatic)

echo '10.50.1.20 ise-01 443' | awk '{printf "%s:%s\n", $1, $3}'
# Output: 10.50.1.20:443\n (newline explicit)