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

Processing arrays using loops

If we have to access all the array elements, we can use a loop that executes once for each element of the array. In other programming languages, where indexes are sequentially numbered, a simple for loop construct is used to access the elements of array. Here, AWK has an associative array, so we use a special type of for loop to go through all the indexes of an array. Its syntax is as follows, followed by a listed explanation of the elements involved:

for (var in array)

body of loop

  • var: This is any variable name, which is set to the index of the corresponding array element.
  • in: This is a keyword.
  • array: This is an array name.
  • body of loop: This is a list of AWK statements that are to be executed. If you want ...

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