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

Printing with fixed column width 

To create a fixed-column-width report, we have to specify a number immediately after the % in the format specifier. This number shows the minimum number of characters to be printed. This is the width (minimum size) of the field. If the input in the field becomes large, it automatically grows to prevent information loss. If the input string is smaller than the specified number, spaces are added to the left.

The following example displays the basic use of printf with fixed column width using the number specified immediately after the %. We have added headers inside the BEGIN statement to make the output more readable, as follows:

$ vi printf_width.awkBEGIN {    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