Text Processing

awk

Processes structured text by fields and patterns.

awk is a small pattern-action language useful for columns, reports, arithmetic, and text extraction.

Syntax
awk 'pattern { action }' [file...]

Arguments explained

  • pattern selects records.
  • action runs for matching records.
  • $1, $2, and so on refer to fields.
  • -F sets the field separator.

Common examples

Print first column
awk '{print $1}' access.log

Prints the first whitespace-separated field from each line.

Use colon separator
awk -F: '{print $1}' /etc/passwd

Prints usernames from /etc/passwd.

awk Command
FieldDetails
Commandawk
CategoryText Processing
Primary useProcesses structured text by fields and patterns.
Syntaxawk 'pattern { action }' [file...]