5.1. What's awk? What's nawk? What's gawk?

Awk is a UNIX/Linux programming language used for manipulating data and generating reports. Nawk is a newer version, and Gawk is the Gnu version. The data may come from standard input, one or more files, or as output from a process. Awk can be used at the command line for simple operations, or it can be written into programs for larger applications. Because awk can manipulate data, it is an indispensable tool used in shell scripts and for managing small databases.

Awk scans a file (or input) line by line, from the first to the last line, searching for lines that match a specified pattern and performing selected actions (enclosed in curly braces) on those lines. If there is a pattern with no specific action, all lines that match the pattern are displayed; if there is an action with no pattern, all input lines specified by the action are executed upon.

Gawk is the Gnu Project's implementation of the awk programming language. It conforms to the definition of the language in the POSIX 1003.2 Command Language And Utilities Standard and to the same awk (nawk) authored by Aho, Kernighan, and Weinberger. Gawk also provides more recent Bell Labs awk extensions and some Gnu-specific extensions.

5.1.1. What Does awk Stand for?

Awk stands for the first initials in the last names of each of the authors of the language, Alfred Aho, Brian Kernighan, and Peter Weinberger. They could have called it wak or kaw, but for whatever reason, awk won out. Gawk stands for the same thing; it's just the Gnu version.

5.1.2. Which awk?

There are a number of versions of awk: old awk, new awk, Gnu awk (gawk), POSIX awk, and so on. Awk was originally written in 1977, and in 1985, the original implementation was improved so that awk could handle larger programs. Additional features include user-defined functions, dynamic regular expressions, processing multiple input files, and more. On most systems, the command is awk if using the old version, nawk if using the new version, and gawk if using the Gnu version. [1] This chapter is based on gawk, the version of awk that is part of the Linux distribution. Version information can be displayed with the --version option to awk.

[1] With Red Hat Linux, the Gnu version, gawk, is linked to awk. This text pertains primarily to the new awk, nawk, with Gnu extensions. The Gnu implementation, gawk, is fully upward-compatible with nawk.

Example 5.1.
% awk --version
						GNU Awk 3.0.3
						Copyright (C) 1989, 1991-1997 Free Software Foundation.
						This program is free software; you can redistribute it and/or modify
						it under the terms of the GNU General Public License as published by
						the Free Software Foundation; either version 2 of the License, or
						(at your option) any later version.
						This program is distributed in the hope that it will be useful, 
						but WITHOUT ANY WARRANTY; without even the implied warranty of
						MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
						GNU General Public License for more details.
						You should have received a copy of the GNU General Public License
						along with this program; if not, write to the Free Software
						Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-
						1307, USA.
					

On many systems the command, awk, is linked tothe version being used. When describing awk and its many features, we will use the command awk, assuming that it is linked to gawk as shown in the following example.

Example 5.2.
% ls -l /bin/awk
						lrwxrwxrwx   1 root    root        4 May 12 04:47 /bin/awk -> gawk
					

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.153.212