Awk Language

AWK is a LittleLanguage. It's described in The Awk ProgrammingLanguage (ISBN 020107981X ) 1988. From the AWK FAQ at:

awk is a programming language with strong support for text pattern matching, named after its three original authors:
A: AlfredAho
W: PeterWeinberger
K: BrianKernighan

they write:
"Awk is a convenient and expressive programming language that can be applied to a wide variety of computing and data-manipulation tasks."

It was used for many of the same kinds of text processing tasks that Perl is used for, and Perl was partially based on it.

Most implementations of awk are interpreters which read your awk source program and parse it and act on it directly.

Awk is still maintained by BrianKernighan, with the last bug fix 20110810 It could have been WAK.

{Or KAW. KAW would have been great.}

Too bad there is not a Nelson in the group. Then you'd have fun commands like


An awk program is essentially a list of patterns with associated code. The program is run against an input file. Each line of the input file is compared against each of the patterns, and the code for all of the matching patterns executed.

Awk is an excellent language for writing short Unix filters for text files. However, if you require more extravagant processing, it's quite likely that you need Perl. (You will have difficulty in opening more than one file in many of the "stricter" dialects of awk.)

Do you know about the 'getline' command? With it, you can open files independent of the main "loop". Reading a file is as simple as:
  while((getline < "somefile") > 0) {
	do stuff
If you don't care about error processing (when getline might return -1) then you can use
  while(getline < "somefile") {
	do stuff

In GAWK, the GNU extended version, getline can read from a co-process.

There are those who do more sophisticated processing in AWK than in Perl. Some people find it easier to write, easier to read, and easier to convert to C if eventually needed.

-- Ben Tremblay

AWK's use of patterns to decide what actions to fire is inherited (and improved) from SNOBOL. The SnobolLanguage used the concept of "success" or "failure" (of pattern matches, or comparison operators such as GT() and LEQ, or many other operations) to control GOTOs. A typical SNOBOL program was written in a style that would be very familiar to an AWK programmer: perform a pattern match; if it succeeds, execute this block, otherwise skip it.

I used to use awk a lot, and it was fine, but since I always install perl on any machine I am likely to use much, I don't use awk anymore. Am I making a mistake?

I doubt it. There's a tool called a2p in the perl toolset which converts awk scripts into perl. So you can even use perl to run your awk scripts.

If it is do-able in Awk, it's a joy compared to Perl. Why muck around with those ugly $'s @'s %'s {}'s ;'s all over the place when they are simply not needed? Compare:
  for(i in arr) print i, arr[i]   # clean, crisp
  for $i (keys %hash) { print "$i $hash{$i}\n" ; }  # and did you notice it was %hash and $hash at the same time ... wtf
Of course, awk can't do everything .. shame, it's syntax is the best (with the exceptiono of how it manages multi-dimensional arrays - cumbersome**2 )

I started learning awk from reading some joke text file on the old Wiretap etext archive, which described how certain sysadmins solved certain problems. And some of them were like:
 kill -9 `ps -a | awk '/xtrek/{print $1}'`
There is a little program called pkill, now part of every standard UNIX, which first appeared on Solaris and solves that exact problem. Try pkill xtrek

Awk and Wiki share a certain gestalt. Within their domains, they are deceptively simple, clean and flexible. While quite capable on its own, Awk was originally written in the context of Unix. Through simple syntax, it can access the power of the Unix command line.

AwkiAwki takes advantage of this synergy to: According to Andrew Sumner's tests, Awk is no longer a performance slouch, either -- JimHart(

HenrySpencer? wrote an assembler in AWK:

Yacc geeks can learn a lot by reading the awk grammar.

Ok, now I'm curious, so I will...but which awk? Learn what?


Q What is a inexpensive and simple tool for developers with MicrosoftWindowsCulturalAssumption that will do things similar to AwkLanguage? Would VbScript do, now that it has RegularExpression capabilities? Please do not suggest tools that require ExtensibleMarkupLanguage if possible.

A You can get a free and open source version of awk itself for windows, see the GNU version at According to HansWobbe AwkLanguage is very appropriate to handle WikiMarkUp. See also AwkiAwki.

See also: PerlLanguage (arguably a descendant), SnobolLanguage (an antecedent), PowerOfPlainText

View edit of October 3, 2014 or FindPage with title or text search