gawk: Getline/Variable/Pipe
4.10.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.
According to POSIX, 'EXPRESSION | getline VAR' is ambiguous if
EXPRESSION contains unparenthesized operators other than '$'; for
example, '"echo " "date" | getline VAR' is ambiguous because the
concatenation operator is not parenthesized. You should write it as
'("echo " "date") | getline VAR' if you want your program to be portable
to other 'awk' implementations.