Go to the first, previous, next, last section, table of contents.
At the most basic level, the job of a program is to process some input data and produce results.
@ifnottex
_______
+------+ / \ +---------+
| Data | -----> < Program > -----> | Results |
+------+ \_______/ +---------+
The "program" in the figure can be either a compiled program(66) (such as @command{ls}), or it may be interpreted. In the latter case, a machine-executable program such as @command{awk} reads your program, and then uses the instructions in your program to process the data.
When you write a program, it usually consists of the following, very basic set of steps:
@ifnottex
______
+----------------+ / More \ No +----------+
| Initialization | -------> < Data > -------> | Clean Up |
+----------------+ ^ \ ? / +----------+
| +--+-+
| | Yes
| |
| V
| +---------+
+-----+ Process |
+---------+
BEGIN rule
(see section The BEGIN and END Special Patterns).
If you were baking a cake, this might consist of laying out all the
mixing bowls and the baking pan, and making sure you have all the
ingredients that you need.
END rule
(see section The BEGIN and END Special Patterns).
After the cake comes out of the oven, you still have to wrap it in
plastic wrap to keep anyone from tasting it, as well as wash
the mixing bowls and other utensils.
An algorithm is a detailed set of instructions necessary to accomplish a task, or process data. It is much the same as a recipe for baking a cake. Programs implement algorithms. Often, it is up to you to design the algorithm and implement it, simultaneously.
The "logical chunks" we talked about previously are called records, similar to the records a company keeps on employees, a school keeps for students, or a doctor keeps for patients. Each record has many component parts, such as first and last names, date of birth, address, and so on. The component parts are referred to as the fields of the record.
The act of reading data is termed input, and that of generating results, not too surprisingly, is termed output. They are often referred to together as "Input/Output," and even more often, as "I/O" for short. (You will also see "input" and "output" used as verbs.)
@command{awk} manages the reading of data for you, as well as the breaking it up into records and fields. Your program's job is to tell @command{awk} what to with the data. You do this by describing patterns in the data to look for, and actions to execute when those patterns are seen. This data-driven nature of @command{awk} programs usually makes them both easier to write and easier to read.
Go to the first, previous, next, last section, table of contents.