Multi-Dimensional Arrays
Two-dimensional array — store by row and column
cat <<'EOF' > /tmp/demo.txt
vault-01 cpu 82
vault-01 mem 64
ise-01 cpu 45
ise-01 mem 71
bind-01 cpu 12
bind-01 mem 38
EOF
awk '{data[$1][$2]=$3} END{for(i in data) for(j in data[i]) print i, j, data[i][j]}' /tmp/demo.txt
Pivot table — cross-tabulate two fields
cat <<'EOF' > /tmp/demo.txt
vault-01 ESTAB
vault-01 ESTAB
vault-01 TIME-WAIT
ise-01 ESTAB
ise-01 CLOSE-WAIT
bind-01 ESTAB
bind-01 ESTAB
bind-01 ESTAB
bind-01 TIME-WAIT
EOF
awk '{pivot[$1][$2]++; total[$1]++} END{for(r in total){printf "%-20s", r; for(c in pivot[r]) printf " %s=%d", c, pivot[r][c]; printf " total=%d\n", total[r]}}' /tmp/demo.txt
Multi-dimensional aggregation — sum by two keys
cat <<'EOF' > /tmp/demo.txt
2026-04 vault-01 1024.50
2026-04 vault-01 512.25
2026-04 ise-01 768.00
2026-03 vault-01 2048.75
2026-03 bind-01 256.00
2026-03 bind-01 128.50
EOF
awk '{sum[$1][$2]+=$3} END{for(i in sum) for(j in sum[i]) printf "%s %s %.2f\n", i, j, sum[i][j]}' /tmp/demo.txt
Connection pivot — ss connections by state and local port
ss -tn | awk 'NR>1 {split($4,a,":"); pivot[$1][a[length(a)]]++} END{for(state in pivot){printf "%-12s", state; for(port in pivot[state]) printf " :%s=%d", port, pivot[state][port]; print ""}}'