Next: , Previous: , Up: Getline   [Contents][Index]


4.9.6 Using getline into a Variable from a Pipe

When you use ‘command | getline var’, the output of 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:

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

In this version of getline, none of the predefined variables are changed and the record is not split into fields. However, RT is set.