O'Reilly logo

Learning AWK Programming by Shiwang Kalkhanda

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using getline to change the output into a variable from a coprocess

Reading input into the getline command through a pipe is one-way communication. The command output is only sent to the AWK program through the pipe in one direction. If we need to send and receive the data from a program in AWK, then we have to use two-way communication using the |& operator. The data from the process is received generally with the help of getline using this process. The following example illustrates how this method works:

$ vi getline_var_coprocess.awkBEGIN    {    cmd = "tr [a-z] [A-Z]"    print "Linux is derived from Unix. Unix is oldest OS" |& cmd    close(cmd, "to")    cmd |& getline    print $0    close(cmd)}$ awk -f getline_var_coprocess.awk

The output of the execution ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required