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

Unary expressions

An operator that accepts a single operand is called a unary operator, and expressions built using unary operator are called unary expressions. Increment and decrement operators also fall under this category.

Unary plus:

It is represented by a single plus (+) symbol. It multiplies a single operand by +1. In the following example, we assign a variable p with value -5. On applying the unary plus operator to the variable, it multiplies the variable p with +1 and again stores the result inside pas follows:

$ awk 'BEGIN{ p = -5; p = +p; print "p = ",p }' 

The output on execution of the preceding code is as follows:

p =  -5 

Unary minus:

It is represented by a single minus (-) symbol. It multiplies a single operand by -1. In the ...

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