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

Redirecting output to a file (>)

This redirection operator (>) prints the items into the output file. Its syntax is as follows:

print items > demo

In this type of redirection, if the output file named demo exists, then it is erased before the first output is written to it. Subsequent write operations to the same file within the same AWK command do not overwrite the content, but append to it. If the output file does not it creates it. For example, with the employee database file, emp.dat, we generate a report with headers columns, as follows:

$ vi printf_redirection1.awkBEGIN {    printf "--------------------------------------------------------------------------------\n"> "emp_report" printf "|%-6s\t|%-6s\t|%-10s\t|%-17s\t|%-3s\t|%-3s\t|%-6s|\n", ...

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