A fast, practical cheat sheet for daily sysadmin, DevSecOps, log analysis, and automation work. Clean, minimal, and designed for rapid recall.
Mental Model (Quick Recall)
pattern
When to run the action
action
What to do (default:
print $0)$1, $2 ... $NF
Individual fields
$0
Whole line
Key Variables
- NR → global line number
- NF → number of fields
Common One-Liners (Daily Use)
Print field(s)
Print field(s)
Prefix output
Prefix output
Print mountpoints only
Print mountpoints only
Skip comments + blank lines
Skip comments + blank lines
Filter rows by value
Filter rows by value
Lines matching regex
Lines matching regex
Field Separators (FS)
Output Formatting (OFS)
Change output separator
Change output separator
Pretty formatting with printf
Pretty formatting with printf
Arithmetic & Aggregation
The
END block executes after all input lines have been processed, making it perfect for aggregations.Conditionals
Key Built-in Variables
| Variable | Meaning |
|---|---|
$0 | entire line |
$1..$NF | fields |
NF | number of fields |
NR | line number (global) |
FNR | line number per file |
FS | field separator |
OFS | output field separator |
RS | record separator |
ORS | output record separator |
Useful Practical Snippets
Remove duplicate lines
Remove duplicate lines
Extract column and transform
Extract column and transform
Replace text inline
Replace text inline
Print field indexes (debug)
Print field indexes (debug)
Real Sysadmin Examples
Parse fstab quickly
Extract blocked IPs from logs
Show failed SSH attempts
Minimal Recall Table
| Concept | Shortcut |
|---|---|
| Fields | $1..$NF |
| Whole line | $0 |
| Line number | NR |
| Filter rows | condition { print } |
| Set delimiter | -F"," |
| Format output | printf |
| Pre/Post blocks | BEGIN / END |