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 output into a pipe

In this method, the output of a shell command can be piped into the getline using "command" | getline, which can be further used to generate output. The following examples illustrate how this method works:

$ vi getline_pipe.awkBEGIN   {        "date" | getline        print "Date is : ", $0         close("date")        print "====================="        print "DISK FREE SPACE INFO"        print "====================="        # using loop to print multiple lines        while (("df -h" | getline) > 0 )                print "Disk info : ", $0        close("df -h")}$ awk -f getline_pipe.awk 

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

Date is : Wed Mar 7 00:13:17 IST 2018=====================DISK FREE SPACE INFO=====================Disk info : Filesystem Size Used ...

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