Low Orbit Flux Logo 2 F

AWK How To Print Array

As expected, printing an array in AWK is easy.

You can loop over an entire array and print out all elements like this:


awk 'BEGIN { 
   a[0] = "frog"; 
   a[1] = "turtle"; 
   a[2] = "fish"; 
   for (i in a) print i, a[i]
}'

You can print specific columns in an array like this:


awk 'BEGIN {
   array1["ab"] = "cow";
   array1["xy"] = "dog";
   array1[23] = "sheep";
   print array1["ab"] " " array1[23];
}'