Last edit

Summary: Fixed a minor bug, remember, if $i = "0", then ($i) is false while not being an empty string.


< if ($i)


> if ($i != "")

$ is the "field reference" operator in AWK. It references the field in the current input record given by the variable or constant. E.g. if you want to print the first field, the following are equivalent:

# print the first field using the '$' operator and a constant.
print $1;

# same but with a variable instead of a constant
i = 1;
print $i;

The power of awk is in learning to use field references, some further examples:

# print both the value of i, and the field at $i..
print i, $i;

# print the field at $i, but only if it something other than the empty
# string:
if ($i != "")
  print $i;