Printf Statement

You can use the printf command in place of print to control the format of the output that awk generates. The awk version of printf is similar to that of the C language. A printf command takes the following format:

printf "control-string" arg1, arg2, ... , argn

The control-string determines how printf will format arg1 - argn. These arguments can be variables or other expressions. Within the control-string, you can use "\n" to indicate a NEWLINE and "\t" to indicate a TAB.

The control-string contains conversion specifications, one for each argument. A conversion specification has the following format:

%[-][x[.y]]conv

The - causes printf to left justify the argument. The x is the minimum field width, and the .y is the number of places to the right of a decimal point in a number. The conv is a letter from the following list:

Conv Conversion
d decimal
e exponential notation
f floating point number
g use f or e, whichever is shorter
o unsigned octal
s string of characters
x unsigned hexadecimal

[Help] [Provide some feedback] [Go to Previous Page]