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

Reading non-decimal input

The non-decimal values are like octal numbers or hexadecimal numbers. We cannot use these values to print their decimal equivalent with AWK; GAWK provides the option, --non-decimal-data, to print non-decimal values in the output. Octal values need to be prefixed with 0 and hexadecimal values need to be prefixed with 0x for reading in GAWK. For example, the following gawk command can be used to convert hexadecimal input to the corresponding decimal output, as follows:

$ echo 088 | gawk --non-decimal-data '{ printf "Decimal equivalent of octal %s is : %d \n", $1, $1 }'

The output of the previous code is as follows:

Decimal equivalent of octal 088 is : 88 

Simply using print will treat the expression as a string. Although ...

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