100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Programming

What Is AWK?

AWK is a compact, data-driven programming language built for scanning text files line by line and reacting to patterns. It excels at extracting columns, computing summaries, and reshaping structured text.

FoundationsBeginner8 min readJul 10, 2026
Analogies

AWK in a Nutshell

AWK is a domain-specific programming language for processing text that is organized into lines and columns. Instead of writing loops to open a file and read it line by line, you declare patterns and the actions to run when a line matches. AWK handles the reading loop for you, feeding it every line of input automatically. It was created in 1977 at Bell Labs by Alfred Aho, Peter Weinberger, and Brian Kernighan, whose surname initials give the language its name.

🏏

Cricket analogy: Like a wicketkeeper who does not chase every ball but stands ready and reacts only when the ball actually comes to the stumps, AWK sits back and springs into action only on lines that match a pattern.

Why AWK Still Matters

Despite being nearly five decades old, AWK remains preinstalled on virtually every Unix and Linux system, so it is always available when you SSH into a server with nothing else set up. Its sweet spot is quick, one-off transformations of tabular text: pulling the third column out of a log, summing a numeric field, or reformatting comma-separated values. For these tasks a one-line AWK program often replaces a dozen lines of Python or a fragile chain of cut, sort, and paste. Because AWK is stream-oriented it processes files far larger than memory, reading one record at a time.

🏏

Cricket analogy: Like a reliable twelfth man who is always in the dressing room ready to field when needed, AWK is preinstalled and available on any server the moment you need it.

A First Taste

The canonical introductory example prints the first column of every line of input. AWK automatically splits each line into fields on whitespace and names them $1, $2, $3 and so on, with $0 being the entire line. You never write the read loop; the body inside the braces runs once per line. This field-splitting behaviour, combined with implicit iteration, is what makes AWK feel almost declarative for column work.

🏏

Cricket analogy: Selecting $1 from each line is like a scorer noting only the opening batsman's name from every innings sheet, ignoring the rest of the batting order.

bash
# Print the first whitespace-separated field of every line
awk '{ print $1 }' access.log

# $0 is the whole line, $1..$NF are the fields
echo 'alice 42 engineer' | awk '{ print $1, $3 }'
# -> alice engineer

There are several AWK implementations: the original 'one true awk' (BWK awk) by Kernighan, GNU AWK (gawk) which is the most feature-rich and common on Linux, and mawk which is very fast. For portable scripts, stick to POSIX AWK features; use gawk-only extensions only when you know gawk is present.

  • AWK is a data-driven language for scanning text organized into lines (records) and columns (fields).
  • It was created in 1977 at Bell Labs; the name comes from Aho, Weinberger, and Kernighan.
  • You declare patterns and actions; AWK supplies the line-reading loop automatically.
  • Fields are auto-split on whitespace and accessed as $1, $2, ...; $0 is the whole line.
  • It is preinstalled on nearly all Unix/Linux systems and processes files larger than memory as a stream.
  • Common implementations include one-true-awk, gawk (GNU), and mawk.

Practice what you learned

Was this page helpful?

Topics covered

#Programming#AWKStudyNotes#WhatIsAWK#AWK#Nutshell#Still#Matters#StudyNotes#SkillVeris#ExamPrep