Go to the first, previous, next, last section, table of contents.


printf Summary

Conversion specification have the form %[flag][width][.prec]format. Items in brackets are optional.

The awk printf statement and sprintf function accept the following conversion specification formats:

%c
An ASCII character. If the argument used for `%c' is numeric, it is treated as a character and printed. Otherwise, the argument is assumed to be a string, and the only first character of that string is printed.
%d
%i
A decimal number (the integer part).
%e
%E
A floating point number of the form `[-]d.dddddde[+-]dd'. The `%E' format uses `E' instead of `e'.
%f
A floating point number of the form [-]ddd.dddddd.
%g
%G
Use either the `%e' or `%f' formats, whichever produces a shorter string, with non-significant zeros suppressed. `%G' will use `%E' instead of `%e'.
%o
An unsigned octal number (again, an integer).
%s
A character string.
%x
%X
An unsigned hexadecimal number (an integer). The `%X' format uses `A' through `F' instead of `a' through `f' for decimal 10 through 15.
%%
A single `%' character; no argument is converted.

There are optional, additional parameters that may lie between the `%' and the control letter:

-
The expression should be left-justified within its field.
space
For numeric conversions, prefix positive values with a space, and negative values with a minus sign.
+
The plus sign, used before the width modifier (see below), says to always supply a sign for numeric conversions, even if the data to be formatted is positive. The `+' overrides the space modifier.
#
Use an "alternate form" for certain control letters. For `o', supply a leading zero. For `x', and `X', supply a leading `0x' or `0X' for a non-zero result. For `e', `E', and `f', the result will always contain a decimal point. For `g', and `G', trailing zeros are not removed from the result.
0
A leading `0' (zero) acts as a flag, that indicates output should be padded with zeros instead of spaces. This applies even to non-numeric output formats. This flag only has an effect when the field width is wider than the value to be printed.
width
The field should be padded to this width. The field is normally padded with spaces. If the `0' flag has been used, it is padded with zeros.
.prec
A number that specifies the precision to use when printing. For the `e', `E', and `f' formats, this specifies the number of digits you want printed to the right of the decimal point. For the `g', and `G' formats, it specifies the maximum number of significant digits. For the `d', `o', `i', `u', `x', and `X' formats, it specifies the minimum number of digits to print. For the `s' format, it specifies the maximum number of characters from the string that should be printed.

Either or both of the width and prec values may be specified as `*'. In that case, the particular value is taken from the argument list.

See section Using printf Statements for Fancier Printing.


Go to the first, previous, next, last section, table of contents.