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

CONVFMT and OFMT

CONVFMT is used to control number-to-string conversion—that is, when a number is converted to a string, AWK will use the CONVFMT format to decide how to print the values. CONVFMT has its default value set as %.6gwhich implies a total of six characters, including both sides of a dot in a number. This variable was added in POSIX-compliant AWK. We can print the value contained in the format specifier CONVFMT variable with the help of the following command:

$ awk 'BEGIN { print "Conversion Format =", CONVFMT}'

The output of the execution of this command is as follows:

Conversion Format = %.6g 

When we use g as the format specifier, it counts all the characters on both sides of the dot. For example, %.4g means a total of 4 characters ...

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