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 pipe

In this method, we store the output of a command sent through a pipe to getline as a variable instead of storing it in $0. Its syntax is command | getline var. The following example shows how this method works:

$ vi getline_var_pipe.awkBEGIN   {        "date" | getline current_time        print "Date is : ", current_time        close("current_time")}$ awk -f getline_var_pipe.awk

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

Date is :  Wed Feb  7 23:31:01 IST 2018

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