gawk: Getline/Coprocess

1 
1 4.10.7 Using 'getline' from a Coprocess
1 ---------------------------------------
1 
1 Reading input into 'getline' from a pipe is a one-way operation.  The
1 command that is started with 'COMMAND | getline' only sends data _to_
1 your 'awk' program.
1 
1    On occasion, you might want to send data to another program for
1 processing and then read the results back.  'gawk' allows you to start a
1 "coprocess", with which two-way communications are possible.  This is
1 done with the '|&' operator.  Typically, you write data to the coprocess
1 first and then read the results back, as shown in the following:
1 
1      print "SOME QUERY" |& "db_server"
1      "db_server" |& getline
1 
1 which sends a query to 'db_server' and then reads the results.
1 
1    The values of 'NR' and 'FNR' are not changed, because the main input
1 stream is not used.  However, the record is split into fields in the
1 normal manner, thus changing the values of '$0', of the other fields,
1 and of 'NF' and 'RT'.
1 
1    Coprocesses are an advanced feature.  They are discussed here only
1 because this is the minor node on 'getline'.  ⇒Two-way I/O, where
1 coprocesses are discussed in more detail.
1