gawk: Getline/Variable/Pipe

1 
1 4.10.6 Using 'getline' into a Variable from a Pipe
1 --------------------------------------------------
1 
1 When you use 'COMMAND | getline VAR', the output of COMMAND is sent
1 through a pipe to 'getline' and into the variable VAR.  For example, the
1 following program reads the current date and time into the variable
1 'current_time', using the 'date' utility, and then prints it:
1 
1      BEGIN {
1           "date" | getline current_time
1           close("date")
1           print "Report printed on " current_time
1      }
1 
1    In this version of 'getline', none of the predefined variables are
1 changed and the record is not split into fields.  However, 'RT' is set.
1 
1    According to POSIX, 'EXPRESSION | getline VAR' is ambiguous if
1 EXPRESSION contains unparenthesized operators other than '$'; for
1 example, '"echo " "date" | getline VAR' is ambiguous because the
1 concatenation operator is not parenthesized.  You should write it as
1 '("echo " "date") | getline VAR' if you want your program to be portable
1 to other 'awk' implementations.
1