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

Sending output on other commands using pipe (|)

We can send the output of print command to another program using pipe instead of sending it to a file. For example, we can sort the first name of employees from the emp.dat file by piping the output of the first column to the sort command, and then storing it in a file. We will first display the names in alphabetical order, and in the next example we will store them in a file instead of printing on screen, as follows:

$ awk '{ printf "%s\n", $1 | "sort" }' emp.dat

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

AmitAmyAnaBillyEmilyEvaGinnyHariJackJaneJohnJulieSamVictorVina

The following stores the result in file names.sorted instead of displaying on screen, as follows:

$ awk '{ ...

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