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


Using the print action for output

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

So far, print has been the only action discussed. As you have seen, print can display an entire record. It can also display selected fields of the record, as in:
$2 == "bridge" { print $1 }
This displays the first field of every record with a second field that is bridge. The output is:
Jim
Linda
Lori
print can display more than a single field. If you give print a list of fields separated by commas, as in:
$1 == "Jim" { print $2,$3,$4 }
print displays the given fields separated by single blanks, as in:
reading 15 100.00
bridge 4 10.00
role playing 5 70.00
The print action can display strings and numbers along with fields. For example:
$1 == "John" { print "$",$4 }
prints:
$ 100.00
$ 30.00
In this instruction, the print action prints a string containing a $, followed by a blank, followed by the value of the fourth field in each selected record.
As an exercise, predict the output of the following:
(a)  $1 == "Lori" { print $1,"spends $", $4,"on",$2 }
(b)  $2 == "jogging" { print $1,"jogs",$3,"hours a week" }
(c)  $4 > 100.00 { print $1, "has an expensive hobby" }
You can check your predictions by running these programs against the hobbies file.

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014