Go to the first, previous, next, last section, table of contents.


Using getline Into a Variable from a Pipe

When you use `command | getline var', the output of the command command is sent through a pipe to getline and into the variable var. For example, the following program reads the current date and time into the variable current_time, using the date utility, and then prints it.

awk 'BEGIN {
     "date" | getline current_time
     close("date")
     print "Report printed on " current_time
}'

In this version of getline, none of the built-in variables are changed, and the record is not split into fields.


Go to the first, previous, next, last section, table of contents.