awk '{print $1}' <file>Prints the first whitespace-separated field of each line — the client IP in a web log.
Example
awk '{print $1}' access.logA pattern-scanning language for column-based text: extract fields, compute totals and reformat output.
sudo apt install gawkawk '{print $1}' <file>Prints the first whitespace-separated field of each line — the client IP in a web log.
Example
awk '{print $1}' access.logawk '{print $1, $NF}' <file>Prints the first and last field; NF is the number of fields.
Example
awk '{print $1, $NF}' data.txtawk -F'<sep>' '{print lt;n>}' <file>Sets a custom field separator — here, user names and login shells.
Example
awk -F: '{print $1, $7}' /etc/passwdawk -F, 'NR>1 {print $2}' <file>Skips the header row (NR is the line number).
Example
awk -F, 'NR>1 {print $2}' users.csvawk '/<pattern>/' <file>Prints lines matching a regex, like grep.
Example
awk '/Failed password/' /var/log/auth.logawk 'lt;n> <op> <value>' <file>Filters on a field value — here, requests that returned 404.
Example
awk '$9 == 404' access.logawk -F: '$3 == 0' /etc/passwdFinds every account with UID 0. Anything other than root is a red flag.
awk -F: '$7 !~ /nologin|false/' /etc/passwdLists accounts that have a real login shell.
awk 'length > <n>' <file>Prints lines longer than n characters.
Example
awk 'length > 200' app.logawk '{sum += lt;n>} END {print sum}' <file>Sums a column — here, total bytes sent.
Example
awk '{sum += $10} END {print sum}' access.logawk '{c[$1]++} END {for (k in c) print c[k], k}' <file> | sort -rnCounts occurrences of each value — the top requesting IPs.
Example
awk '{c[$1]++} END {for (k in c) print c[k], k}' access.log | sort -rn | headawk 'END {print NR}' <file>Counts lines, like wc -l.
Example
awk 'END {print NR}' targets.txtawk '!seen[$0]++' <file>Removes duplicate lines while keeping the original order.
Example
awk '!seen[$0]++' urls.txtA stream editor for filtering and transforming text: substitutions, deletions and in-place file edits.
Extracts columns, fields or characters from each line of input.
Searches text for lines matching a pattern, with regular expressions, recursion and context.
A lightweight command-line JSON processor: filter, transform and pretty-print JSON from APIs, logs and tool output.
Builds and runs command lines from standard input — the glue for batch operations and parallel jobs in pipelines.