Escaping Patterns
Escaping patterns I’ve actually used. Every entry has a date and context.
2026-03-22: AsciiDoc stem:[] Brackets
Problem: MathJax error "Could not find closing ']'" in formulas.adoc
Context: College algebra documentation, fractional exponents
The Fix:
// WRONG - AsciiDoc parses [n] as attribute
stem:[\sqrt[n]{a}]
// RIGHT - escape both brackets
stem:[\sqrt\[n\]{a}]
Rule: In inline \$...\$, always escape nth root brackets: \sqrt\[n\]
Worklog: WRKLOG-2026-03-22
2026-03-07: sed Pipe Delimiter for Paths
Problem: Escaping hell with slashes in XML path substitution
Context: WLC VM migration, updating qemu paths in libvirt XML
The Fix:
# WRONG: escaping nightmare
sed -i 's/\/usr\/bin\/qemu-system-x86_64/\/usr\/libexec\/qemu-kvm/' file.xml
# RIGHT: use pipe delimiter
sed -i 's|/usr/bin/qemu-system-x86_64|/usr/libexec/qemu-kvm|' file.xml
Rule: When substituting paths, use | or # as delimiter instead of /
Worklog: WRKLOG-2026-03-07
2026-03-05: awk PEM Certificate Chain Split
Problem: Need to extract individual certs from a chain file
Context: ISE certificate deployment, splitting chain.pem into leaf/issuing/root
The Fix:
# Extract first cert (leaf)
awk '/-----BEGIN CERTIFICATE-----/{n++} n==1' chain.pem > leaf.pem
# Extract second cert (issuing CA)
awk '/-----BEGIN CERTIFICATE-----/{n++} n==2' chain.pem > issuing-ca.pem
# Extract third cert (root CA)
awk '/-----BEGIN CERTIFICATE-----/{n++} n==3' chain.pem > root-ca.pem
How it works: Counter n increments each time BEGIN CERTIFICATE is seen. n==1 prints only while counter equals 1 (first cert block).
Worklog: WRKLOG-2026-03-05
2026-03-05: awk Field Separator for Dots
Problem: Split IP address or FQDN by dots
Context: Network diagnostics, parsing ip command output
The Fix:
# WRONG: dot is regex "any char"
awk -F'.' '{print $1}' file
# RIGHT: escape the dot
awk -F'\\.' '{print $1}' file
# ALSO RIGHT: use bracket (more readable)
awk -F'[.]' '{print $1}' file
Rule: -F takes a regex. Dots must be escaped or bracketed.
Worklog: WRKLOG-2026-03-05
2026-03-05: awk Pipe Field Separator
Problem: Parse pipe-delimited output
Context: Parsing switch/router show commands
The Fix:
# WRONG: pipe is regex alternation
awk -F'|' '{print $1}' file
# RIGHT: escape or bracket
awk -F'\\|' '{print $1}' file
awk -F'[|]' '{print $1}' file
Worklog: WRKLOG-2026-03-05
2026-03-05: grep -E Multiple Alternations
Problem: Match any of several VLAN interfaces
Context: VyOS troubleshooting, checking multiple subinterfaces
The Fix:
# Match eth0.20 OR eth0.30 OR eth0.40
show interfaces | grep -E 'eth0\.(20|30|40)'
# The dot needs escaping (literal dot, not "any char")
# Parentheses group the alternation
Worklog: WRKLOG-2026-03-05
2026-03-01: awk Line Range with Buffer
Problem: Show first 5 and last 5 lines of a file with line numbers
Context: Quick file inspection without loading entire file
The Fix:
awk 'NR<=5 {print NR": "$0; next} {buf[NR]=$0} END {print "..."; for(i=NR-4;i<=NR;i++) print i": "buf[i]}' file
How it works: - First 5 lines: print immediately with line number - Remaining lines: store in buffer array (overwrites, keeping only recent) - END: print last 5 from buffer
Worklog: WRKLOG-2026-03-01