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

The sprintf (format, expression) function

The sprintf() function is similar to the printf() function and uses the same format specifications as printf(), with the only difference being that instead of printing the output on the screen, it returns a string that can be assigned to a variable. The following example illustrates the usage of the sprintf() function:

$ vi sprintf.awkBEGIN    {    for (  i = 97; i <= 122; i++ )     {    char = sprintf( "%c", i );    printf("%s ", char )    }     print}$ awk -f sprintf.awk

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

a b c d e f g h i j k l m n o p q r s t u v w x y z 

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