← Files & Text
Linux · Files & Text
How to process columns and fields with awk in Linux
Extract columns, filter rows, and compute sums with awk, including a custom field separator.
awk splits each line into fields ($1, $2, and so on) and lets you filter and compute. It is the go-to for column data and quick sums.
# Print the first and third columns
awk '{print $1, $3}' <file>
# Custom separator (e.g. /etc/passwd)
awk -F: '{print $1, $7}' /etc/passwd
# Only rows where column 3 is over 100
awk '$3 > 100 {print}' <file>
# Sum a column
awk '{sum += $1} END {print sum}' <file>LinuxawkText