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

The length (string) function is used to calculate the length of a string. If the string is a number, the length of the digits in the string representing the number is returned—for example:

$ vi length1.awkBEGIN    {    print "Example of length calculation of string"    print "length(hello..!) : "  length("hello..!")    print "Example of length calculation of number"    print "length(10*20) : " length(10*20)
}$ awk -f length1.awk

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

Example of length calculation of stringlength(hello..!) : 8Example of length calculation of numberlength(10*20) : 3

If no argument is given to the length function, then it returns the length of $0. For example, we can use the length function ...

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