Powerful text processing language for pattern scanning and field-based reporting.
low risk
awk processes text line-by-line, splitting each into fields ($1, $2, etc.) by a delimiter (default: whitespace). Supports conditionals, loops, and arithmetic — ideal for log analysis, report generation, and structured text extraction.
| Flag | Meaning |
|---|---|
-F | Set field separator (-F: for colon-delimited files like /etc/passwd) |
-v | Assign a variable before program execution |
-f | Read awk program from a file |
awk '{print $1, $NF}' access.logPrint first and last field from each line (e.g. IP and status code) · explain & risk-check →awk -F: '$3 >= 1000 {print $1}' /etc/passwdList all usernames with UID >= 1000 (regular users) · explain & risk-check →awk '/ERROR/{count++} END{print count}' app.logCount ERROR occurrences in a log file · explain & risk-check →`awk 'NR==FNR{a[$0];next} $0 in a'` finds common lines between two files — a classic awk idiom for set intersection without sorting.
Reference text is hand-written and may be incomplete — check man awk for your version. Test destructive commands on a non-production system first.