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 strtonum (string) function

This function is used to examine an argument supplied as a string and returns its numeric value. If the string supplied begins with a leading 0, it is treated as an octal number. If the string begins with a leading 0x, it is treated as a hexadecimal number. The following example illustrates the working strtonum() function:

$ vi strtonum.awkBEGIN    {    print "Decimal num strtonum(123)    : ", strtonum(123)    print "Octal num strtonum(0123)     : ", strtonum(0123)    print "Hexadecimal num strtonum(0x123)  : ", strtonum(0x123)}$ awk -f strtonum.awk

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

Decimal num strtonum(123)    :  123Octal num strtonum(0123)     :  83Hexadecimal num strtonum(0x123)  :  291

Apart from the preceding ...

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