awk 'pattern { action }' [file...]Arguments explained
- pattern selects records.
- action runs for matching records.
- $1, $2, and so on refer to fields.
- -F sets the field separator.
Common examples
awk '{print $1}' access.logPrints the first whitespace-separated field from each line.
awk -F: '{print $1}' /etc/passwdPrints usernames from /etc/passwd.
| Field | Details |
|---|---|
| Command | awk |
| Category | Text Processing |
| Primary use | Processes structured text by fields and patterns. |
| Syntax | awk 'pattern { action }' [file...] |