Description #
Awk is a domain-specific language designed for text processing and data extraction. It is especially powerful for working with column-based data and is widely used in Unix-like environments for report generation, pattern scanning, and scripting.
History #
Awk was developed in 1977 at Bell Labs by Alfred Aho, Peter Weinberger, and Brian Kernighan — the language name derives from their initials (A, W, and K). It became an essential part of Unix toolkits and is known for its concise, expressive syntax tailored for line-by-line data manipulation.
Hello World Code #
BEGIN { print "Hello, World!" }
How to Run #
Option 1: Online
Option 2: Local
- Save the script in a file called
hello.awk
:
BEGIN { print "Hello, World!" }
Run the script:
awk -f hello.awk
Key Concepts #
- Pattern-action syntax
- Works line-by-line through input files or streams
- Built-in variables like
NR
,NF
, andFS
- Strong string processing capabilities
- Associative arrays (hash maps)
- Regular expression matching
- Field-based data extraction
- Arithmetic and control structures
- Text substitution and formatting
- Integrates with shell pipelines
Try It Online #
Fun Facts #
- Awk scripts can often replace full-fledged programs with just a few lines.
- Brian Kernighan used Awk in many examples in his famous Unix programming books.
- GNU Awk (gawk) is the most popular modern implementation, adding extra features.