AWK Operators Assignment Operators - AWK

What is AWK - Assignment Operators?

AWK supports the following assignment operators −

Simple Assignment

It is represented by =. The following example demonstrates this −

Example

On executing this code, you get the following result −

Output

Shorthand Addition

It is represented by +=. The following example demonstrates this −

Example

On executing this code, you get the following result −

Output

In the above example, the first statement assigns value 10 to the variable cnt. In the next statement, the shorthand operator increments its value by 10.

Shorthand Subtraction

It is represented by -=. The following example demonstrates this −

Example

In the above example, the first statement assigns value 100 to the variable cnt. In the next statement, the shorthand operator decrements its value by 10.

Shorthand Multiplication

It is represented by *=. The following example demonstrates this −

Example

On executing this code, you get the following result −

Output

In the above example, the first statement assigns value 10 to the variable cnt. In the next statement, the shorthand operator multiplies its value by 10.

Shorthand Division

It is represented by /=. The following example demonstrates this −

Example

On executing this code, you get the following result −

Output

In the above example, the first statement assigns value 100 to the variable cnt. In the next statement, the shorthand operator divides it by 5.

Shorthand Modulo

It is represented by %=. The following example demonstrates this −

Example

On executing this code, you get the following result −

Output

Shorthand Exponential

It is represented by ^=. The following example demonstrates this −

Example

On executing this code, you get the following result −

Output

The above example raises the value of cnt by 4.

Shorthand Exponential

It is represented by **=. The following example demonstrates this −

Example

On executing this code, you get the following result −

Output

This example also raises the value of cnt by 4.

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

AWK Topics