Normally, awk reads its input one line, or record, at a time; a record is, by default, a sequence of characters ending with a newline. Then awk splits each record into fields, where, by default, a field is a string of non-blank, non-tab characters.
As input for many of the awk programs in this topic's sections, we use a file called countries, which contains information about the ten largest countries in the world. (See ``The sample input file countries''.)
Each record contains the name of a country, its area in thousands of square miles, its population in millions, and the continent on which it is located. (Data are from 1978; the U.S.S.R. has been arbitrarily placed in Asia.) The white space between fields is a tab in the original input; a single blank separates North and South from America .
The sample input file countries
This file is typical of the kind of data awk is good at processing--a mixture of words and numbers separated into fields by blanks and tabs.
The number of fields in a record is determined by the field separator. Fields are normally separated by sequences of blanks and/or tabs, so that the first record of countries would have four fields, the second five, and so on. It is possible to set the field separator to just tab, so each line would have four fields, matching the meaning of the data; we will show how to do this shortly. For the time being, we will use the default: fields separated by blanks and/or tabs. The first field within a line is called $1, the second $2, and so forth. The entire record is called $0.