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

The close (filename [to/from]) function

The close function is used to close the file. The argument to close could also be a shell command used for creating coprocesses, or for redirecting to or from a pipe, or it could be a coprocess or pipe that is used to close a file. The second argument to the close() function is the GAWK extension. The following example illustrates how the close() function works:

$ vi close1.awkBEGIN    {    cmd = "wc"    print "Linux is derived from Unix. Unix is oldest OS." |& cmd    close(cmd, "to")    cmd |& getline var    print var    close(cmd);}$ awk -f close1.awk

The output of the execution of the previous code is as follows:

     1       9      47

In the previous example, the print command provides the input to the wc command. The |& indicates ...

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