Advanced Package: gawk / mawk

awk

Pattern-scanning and text-processing language.

Syntax

awk [options] "program" [file...]

Description

awk splits each line of input into fields and lets you write small programs to filter, transform or summarise columnar data, making it especially good at reports built from log files or command output.

Examples

awk "{print $1}" file.txt
Print just the first column/field of every line
awk -F: "{print $1}" /etc/passwd
Use a custom field separator (colon) to print usernames
df -h | awk "{print $5, $1}"
Combine with another command to extract specific columns

Applies to

Ubuntu Debian Linux Mint RHEL CentOS / Rocky / AlmaLinux Fedora Arch Linux openSUSE Alpine Linux