Skip to main content

Command referenceawk

awk command (Linux / bash / sh / zsh)

Linuxbashshzshtextintermediate

What it does

Process record-oriented text with patterns, fields, and actions. When people search for the awk command linux tutorial, they usually want awk's everyday flags, safe examples, and how it differs from related tools. Below you'll find syntax, options, and copyable examples for Bash/sh/zsh.

Process record-oriented text with patterns, fields, and actions.

Syntax

awk [OPTION] 'PROGRAM' [FILE...]

Common options

Flag / optionMeaning
-F SEPSet the input field separator.
-v VAR=VALUEAssign a variable before processing.
-f FILERead the awk program from a file.
--posixUse strict POSIX behavior.

Practical examples

Print a column

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

Prints the second CSV-like field.

Sum values

awk '{sum += $1} END {print sum}' totals.txt

Adds the first field from every record.

Filter processes

ps aux | awk '$3 > 50 {print $2, $11}'

Shows processes using more than 50 percent CPU.

Common mistakes

  • Treating basic field splitting as a complete CSV parser when values can contain quoted commas.
  • Using double quotes around the program and accidentally expanding shell variables.

FAQ

What does awk do in Linux?

Process record-oriented text with patterns, fields, and actions.

How do I use awk from the terminal?

Start with `awk [OPTION] 'PROGRAM' [FILE...]`, then choose only the options needed for the task.

What is a practical awk example?

Try `awk -F, '{print $2}' users.csv` — Prints the second CSV-like field.

Can I use awk in a shell script?

Yes. awk works in Bash, sh, and Zsh, but scripts should handle quoting, errors, and command output explicitly.

Browse the full Linux and Windows command reference to search more bash, CMD, PowerShell, Conda, and GitHub CLI commands.