$linuxjunkies
>

awk pattern

A pattern in awk that specifies which input lines should be processed by an action; it's a condition that matches lines based on regular expressions, comparisons, or other criteria.

An awk pattern is a condition placed before an action block that determines whether that action executes for a given input line. Patterns can be simple (like a regex match) or complex (like numeric comparisons or logical expressions). If no pattern is specified, the action runs on every line.

Common pattern types include regular expressions enclosed in slashes (/regex/), comparison expressions ($1 > 100), range patterns (/start/,/end/), and special patterns like BEGIN and END. For example: awk '/error/ { print }' logfile prints only lines matching "error".

Patterns can also be combined with logical operators: awk '$2 > 50 && /warning/ { count++ }' file increments a counter only for lines where the second field exceeds 50 AND the line contains "warning".

Related terms