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 hash modifier (#)

This works with format control letters. For %o octal notation it adds a leading zero in the output. For %x and %X hexadecimal format control characters it adds a leading 0x or 0X, respectively for a nonzero result. For %e, %E, %f, and %F, the result always contains a decimal point. For %g and %G, trailing zeros are not removed from the result. The following example illustrates the workings of a hash (#) modifier:

$ vi printf_hash_modifier.awk BEGIN    {        printf "Octal representation = %#o\n", 10    printf "Hexadecimal representation = %#X\n", 10    printf "Trailing zeros in %% g = %#g\n", 10}$ awk -f printf_hash_modifier.awk

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

Octal representation = 012Hexadecimal representation ...

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