Introducing UNIX and Linux |
AwkOverview |
Invoking 'awk'Just as with Grep and Sed, simple use of Awk involves a
script containing the commands that Awk uses. This
script can either be a string that is an argument to
The data which the Awk script will process is either piped from standard input, or is contained in one or more files given as arguments to the command. The data is divided into records, each of which is subdivided into fields. Unless otherwise stated, each record is a single line of the data, and fields will be separated by whitespace. For instance, to represent students with their marks, a dataset might look like: Cringle Chris 14 75 33 Smith Sam 56 58 45 Jones Jo 9 63 51 This data contains three records (lines), each record containing five fields (columns of text). An Awk script consists of a sequence of pairs
pattern where either the pattern or the action can be omitted. The data is read, record by record, and each record that matches a pattern in the script causes the corresponding action to be performed. If the pattern is omitted the action is performed on every single line of input data. For the rest of this chapter we shall concentrate on the format of the script, and assume that data is piped from standard input. The simplest Awk script is {} which will do precisely nothing for each line of data - the
effect is indistinguishable from
awk -f awkfile or by awk ' ' (not forgetting the conventions for single and double quotes)
where the script is a string following |
Copyright © 2002 Mike Joy, Stephen Jarvis and Michael Luck