If you are like many computer users, you frequently would like to make changes in various text files wherever certain patterns appear, or extract data from parts of certain lines while discarding the rest. To write a program to do this in a language such as C or Pascal is a time-consuming inconvenience that may take many lines of code. The job may be easier with awk.
The awkutility interprets a special-purpose programming language that makes it possible to handle simple data-reformatting jobs easily with just a few lines of code.
The GNU implementation of awk is called gawk; it is fully upward compatible with the System V Release 3.1 and later version of awk. All properly written awk programs should work with gawk. So we usually don't distinguish between gawk and otherawk implementations in this manual.
This manual teaches you what awk does and how you can use awk effectively. You should already be familiar with basic system commands such as ls. Using awk you can:
• manage small, personal databases,
• generate reports,
• validate data,
• produce indexes, and perform other document preparation tasks,
• even experiment with algorithmsthat can be adapted later to other computer languages!
History of awk and gawk
The name awk comes from the initials of its designers: Alfred V. Aho, Peter J. Weinberger, and Brian W. Kernighan. The original version of awk was written in 1977. In 1985 a new version made the programming language more powerful, introducing user-defined functions, multiple input streams, and computed regularexpressions. This new version became generally available with System V Release 3.1. The version in System V Release 4 added some new features and also cleaned up the behaviour in some of the "dark corners" of the language.
The GNU implementation, gawk, was written in 1986 by Paul Rubin and Jay Fenlason, with advice from Richard Stallman. John Woods contributed parts of the code as well. In 1988 and1989, David Trueman, with help from Arnold Robbins, thoroughly reworked gawk for compatibility with the newer awk.
Many people need to be thanked for their assistance in producing this manual. Jay Fenlason contributed many ideas and sample programs. Richard Mlynarik and Robert Chassell gave helpful comments on drafts of this manual. The paper A Supplemental Document for awk by John W. Pierce ofthe Chemistry Department at UC San Diego, pinpointed several issues relevant both to awk implementation and to this manual, that would otherwise have escaped us.
Finally, we would like to thank Brian Kernighan of Bell Labs for invaluable assistance during the testing and debugging of gawk, and for help in clarifying several points about the language.
GNU General Public License
Version 1,February 1989
Copyright (C) 1989 Free Software Foundation, Inc.
675 Mass Ave, Cambridge, MA 02139, USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended toguarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too.
When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License isdesigned to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the...