LockerGnomeTech news and nostalgia for today's technology professionals
Subscribe

Search

Retroawkunixprogramming

Awk’s Authors Used Their Own Names to Demonstrate Its Search Pattern

The original awk paper searches for Aho, Weinberger and Kernighan, then lets the language’s default action print the matches.

Identikit of Chris Pirillo: he slides a fourth face strip into a lineup of three invented strangers' composite faces
Illustration: LockerGnome

The authors put themselves in the search expression. Fair enough. If you are explaining a language named after your own initials, the sample data has already volunteered.

The GNU awk history identifies the designers as Alfred V. Aho, Peter J. Weinberger and Brian W. Kernighan. It dates the original Bell Labs version to 1977.

Their paper demonstrates a regular expression matching the three surnames, with either an uppercase or lowercase initial. Its explanation says the pattern prints lines containing the names “whether capitalized or not.” That describes the initial letters in this example, rather than a general switch to ignore every possible capitalization.

The other trick is what they leave out. The paper says, “If there is no action for a pattern, the matching line is copied to the output.” Awk supplies the input loop and the printing. Your little filter does not need to spell out either one.

Here is the same idea as a runnable command:

awk '/[Aa]ho|[Ww]einberger|[Kk]ernighan/' names.txt

Those are substring searches. A matching surname inside a longer field can still qualify; deciding whether you wanted a whole field is the next job.

The useful sequel is in your own one-liners: which lines exist only because you have forgotten what the tool already does?

More Retro

Every Retro story →