awk Command Generator — Build & Decode awk One-Liners

Extract columns, filter rows, sum or count — and get the exact awk one-liner with every part explained. Or paste an awk command to decode it. Runs in your browser.

Your command

Or: decode an awk command

Paste any awk one-liner — the program gets explained.

How awk thinks: fields and records

awk reads input one line (record) at a time and splits it into fields you reference as $1, $2, … with $0 being the whole line. A program is pattern { action }: the action runs only on lines that match the pattern. awk '{print $1}' prints the first column of every line; awk '/ERROR/ {print $2}' prints the second column of lines containing ERROR.

The separator is the first thing to get right

By default awk splits on any run of whitespace, which is perfect for command output like ls -l or ps. For CSV or /etc/passwd you must set the field separator: -F',' or -F':'. Forget it and $2 won't be what you expect.

Gotchas worth knowing

Frequently asked questions

How do I print a specific column with awk?

awk '{print $2}' file prints the second column. For CSV, add the separator: awk -F',' '{print $2}' file.

How do I sum a column with awk?

awk '{sum += $1} END {print sum}' file adds up column 1 and prints the total once at the end.

How do I filter rows with awk?

Put a pattern before the action: awk '/ERROR/ {print}' for a text match, or awk '$3 > 100' for a numeric condition.

How do I use a comma separator in awk?

awk -F',' '{print $1}'. The -F sets the field separator to a comma for CSV files.

More shell tools: sed, find, curl, or all on the home page.