awklisted
Install: claude install-skill bastos/skills
# GNU awk (gawk) Skill
All output assumes **gawk** (`awk --version` shows GNU Awk). POSIX awk
compatibility is not a goal; gawk extensions are used freely where they help.
---
## Core Principles
1. **Prefer one-liners.** Multi-line awk scripts only when a one-liner becomes
unreadable.
2. **Use `-F` to set the field separator** explicitly. Never assume space.
3. **Dry-run friendly by default.** awk reads and prints; it never edits files
in-place. Redirect explicitly (`> out && mv out in`) when the user wants
in-place behavior.
4. **Use `BEGIN`/`END` blocks** for setup and summary output.
5. **Chain with pipes** when awk alone isn't the cleanest tool.
6. **Never use awk to parse JSON or XML.** Redirect to `jq` / `xmllint` and say
why.
---
## Mental Model
```
awk 'BEGIN { setup } /pattern/ { action } END { summary }' file
```
- awk reads input **line by line** (records, split by `RS`, default `\n`).
- Each record is split into **fields** by `FS` (default: any whitespace).
- `$0` = entire record. `$1`, `$2`, ... `$NF` = individual fields. `NF` = number
of fields. `NR` = current record number. `FNR` = record number within current
file.
---
## Flags
| Flag | Meaning |
|--------------|----------------------------------------------|
| `-F SEP` | Set field separator (string or regex) |
| `-v VAR=VAL` | Set a variable before execution |
| `-f FILE` | Read awk program from a file