awk

Pattern scanning and processing language. Perfect for column extraction, aggregation, and quick reports.

Synopsis

awk [options] 'pattern { action }' file

Core Options

-F, --field-separator

Set field separator (e.g., -F',' for CSV).

-v var=value

Pass variables into the awk program.

-f file

Read awk program from a file.

Usage Examples

Print Columns

Print first and third columns from a space-delimited file.

awk '{print $1, $3}' data.txt

CSV Column

Extract the email column from a CSV file.

awk -F',' '{print $3}' users.csv

Filter Rows

Show lines where the 5th column is greater than 100.

awk '$5 > 100 {print $0}' report.txt

Aggregate Sum

Sum the 2nd column.

awk '{sum += $2} END {print sum}' numbers.txt

Add Headers

Add a header row and format output.

awk 'BEGIN {print "name\tcount"} {print $1 "\t" $2}' stats.txt
Built for builders.