z/OS UNIX System Services User's Guide
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


Assigning values to variables

z/OS UNIX System Services User's Guide
SA23-2279-00

Suppose you want to find out how many people have jogging as a hobby. To do this, you have to look through the hobbies file, record by record, and keep a count of the number of records that have jogging in their second field. This means that you have to remember the count from one record to the next.

awk programs remember information by using variables. A variable is a storage place for information. Every variable has a name and a value. An awk action of the form:
name = value
assigns the specified value to the variable that has the given name. For example:
count = 0
assigns the value 0 to the variable count.
You can use variables in expressions. For example, the value of the expression:
count + 1
is the current value of count, plus 1.

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014