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

Using plus modifier (+) for prefixing with sign/symbol

If we want to prefix all the numeric values, whether they are positive or negative, rather then an optional modifier we put a plus (+) symbol after percentage (%) symbol instead. Positive values will have a plus (+) prefix in output, and negative values will have (-) prefix in output.

For example, we can prefix the salary of all employees in the employee database emp.dat using the plus (+) symbol as follows:

$ awk '{ printf "%s\t%+d\n", $1, $7}' emp.dat

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

Jack    +2000Jane    +1800Eva     +2100Amit    +2350Julie   +2500Ana     +2700Hari    +2350Victor  +2500John    +2200Billy   +1900Sam     +2300Ginny   +2250Emily   +2100Amy     +2500Vina    +2300 

Printing with leading ...

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