Ad space (banner)
🖥️Linux Lessons
Lesson 35 / 61

Extracting a Column with awk

awk is for when "I want to pull a column out of a CSV, and also do more flexible processing on it." awk splits each line into fields on a given delimiter, and can perform flexible processing involving conditions and calculations.

Use it in the form awk -F delimiter '{print $column-number}' filename. -F specifies the delimiter, and $1, $2, and so on specify column numbers.

Running awk -F , '{print$1}' data.csv splits each line of data.csv on commas and extracts just the 1st column from every line.

A common early mistake is reaching for complex awk when a plain cut would've been enough for a simple column extraction, hurting readability. Pick the simplest tool for the job.

In real work, this is used for complex text processing that cut can't handle — computing a per-column total, or processing only rows matching a condition.

Linux
Try it (type this into the pseudo terminal)
awk -F , '{print$1}' data.csv

🧑‍💻 You can type this command into the Linux pseudo terminal to try it yourself (this page itself has no interactive terminal).

Ad space (banner)
Ad space (in-article)