A format specifier starts with the character ‘%’ and ends with
a format-control letter—it tells the printf statement
how to output one item. The format-control letter specifies what kind
of value to print. The rest of the format specifier is made up of
optional modifiers that control how to print the value, such as
the field width. Here is a list of the format-control letters:
%cNOTE: The ‘%c’ format does not handle values outside the range 0–255. On most systems, values from 0–127 are within the range of ASCII and will yield an ASCII character. Values in the range 128–255 may format as characters in some extended character set, or they may not. System 390 (IBM architecture mainframe) systems use 8-bit characters, and thus values from 0–255 yield the corresponding EBCDIC character. Any value above 255 is treated as modulo 255; i.e., the lowest eight bits of the value are used. The locale and character set are always ignored.
%d, %i%e, %Eprintf "%4.3e\n", 1950
prints ‘1.950e+03’, with a total of four significant figures, three of
which follow the decimal point.
(The ‘4.3’ represents two modifiers,
discussed in the next subsection.)
‘%E’ uses ‘E’ instead of ‘e’ in the output.
%fprintf "%4.3f", 1950
prints ‘1950.000’, with a total of four significant figures, three of which follow the decimal point. (The ‘4.3’ represents two modifiers, discussed in the next subsection.)
On systems supporting IEEE 754 floating point format, values
representing negative
infinity are formatted as
‘-inf’ or ‘-infinity’,
and positive infinity as
‘inf’ and ‘infinity’.
The special “not a number” value formats as ‘-nan’ or ‘nan’.
%F%f but the infinity and “not a number” values are spelled
using uppercase letters.
The %F format is a POSIX extension to ISO C; not all systems
support it. On those that don't, gawk uses %f instead.
%g, %G%o%s%u%x, %X%%NOTE: When using the integer format-control letters for values that are outside the range of the widest C integer type, gawk switches to the ‘%g’ format specifier. If --lint is provided on the command line (see Options), gawk warns about this. Other versions of awk may print invalid values or do something else entirely. (d.c.)