Using variables in awk

We can simply declare a variable in the awk script, even without any initialization. Variables can be of type string, number, floating type, and so on. There is no type declaration required such as in C programming. awk will find out the type of variable by its right-hand side data type during initialization or its usage in the script.

Uninitialized variables will have the value 0 or strings will have a value null such as "", depending on how it is used inside scripts:

    name = "Ganesh"
  

The variable name is of the string type:

    j++
  

The variable j is a number. Variable j is initialized to zero and it is incremented by one:

    value = 50
  

The value variable is a number with an initial value of 50.

The technique to modify ...

Get Learning Linux Shell Scripting - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.