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

Increment and decrement expressions

AWK also supports the increment ++ and decrement -- operators; they increase or decrease the value of a variable by one. Both operators are similar to the operators in C. These operators can only be used with a single variable and, thus, only before or after the variable. They are the short forms of some common operations of adding and subtracting.

Pre-increment:

It is represented by the plus plus (++) symbol prefixed to the variable. It increments the value of an operand by one. Let's say we have a variable, var; to pre-increment its value, we write ++var. It first increments the value of operand and then returns the incremented value. In the following example, we use two variables, p =5 and q = ++p.

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