$linuxjunkies
>

awk

also: gawk, mawk, nawk

awk is a text processing language and utility that scans files line-by-line, splits each line into fields, and performs pattern matching and transformations on the data.

awk is a powerful command-line tool for manipulating structured text data. It processes input line-by-line, automatically splitting each line into fields (columns) separated by whitespace or a specified delimiter, then applies rules based on patterns you define.

A typical awk program consists of pattern-action pairs: if a line matches the pattern, the associated action executes. For example, awk '/error/ {print $1, $3}' logfile.txt prints the first and third fields of every line containing "error". awk automatically provides useful variables like NR (line number), NF (number of fields), and $0 (the entire line).

awk excels at reporting, data extraction, and quick calculations without needing a full programming language. It's often used in pipelines: ps aux | awk '{print $1, $11}' displays usernames and commands of running processes.

Related terms