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

Displaying some variables and data

Now, we will look at the values stored in variables or fields using the print command. Its syntax is very simple, print var1, var2,…. Here, var1 and var2 are the variable or field names. A variable can also be an array element. To print the contents of an array, prefix the name of the array with the @ symbol, as follows:

  • print $3: Prints the value stored in field $3
  • print @arrayname: Prints the contents of array arrayname
  • print n1, n2, n3: Prints the value stored in variable n1, n2, and n3

Let's print the value of variables num1, num2 and result in our running program, as follows:

gawk> print num1, num2, resultnum1 = 30num2 = 10result = untyped variable

Here, the result is still not assigned any value, ...

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