AWK
AWK is a classic Unix programming language and command-line tool, created in 1977 by Alfred Aho, Peter Weinberger, and Brian Kernighan, designed for scanning and processing structured text data, especially columnar or line-delimited files.
Definition
AWK is a classic Unix programming language and command-line tool, created in 1977 by Alfred Aho, Peter Weinberger, and Brian Kernighan, designed for scanning and processing structured text data, especially columnar or line-delimited files.
Overview
AWK takes its name from the initials of its creators and was built for a specific, enduring purpose: reading input line by line, automatically splitting each line into fields, and applying pattern-action rules — "when a line matches this pattern, do this action" — which makes it exceptionally well suited to tasks like extracting columns from log files, computing sums and counts, or reformatting delimited text. A typical AWK program is just a few characters, such as `awk '{print $1, $3}' file.txt` to print the first and third fields of every line. AWK sits alongside tools like Sed and grep as a core part of the classic Unix text-processing toolkit, and it's commonly chained with them in shell scripts as part of Unix pipelines. Compared to sed, which is oriented around stream editing and substitution, AWK is a more complete programming language with variables, arrays, control flow, and user-defined functions, making it capable of small but complete data-processing programs, not just single transformations. Despite its age, AWK remains widely used today for quick, ad hoc text and log processing directly from the command line, and its pattern-action model influenced later text-processing tools. GNU AWK (gawk) is the most common modern implementation, extending the original language with additional features while preserving backward compatibility with classic AWK scripts. It is often mentioned alongside Linux in this space.
Key Features
- Automatic line-by-line reading and field splitting
- Pattern-action programming model
- Built-in support for delimited/columnar text processing
- Compact syntax ideal for one-line command-line scripts
- Full programming constructs: variables, arrays, loops, functions
- Commonly chained with other Unix tools in shell pipelines