"<format>", [<arg1>, <arg2>, ..., <argn>]
The format is a character string that contains three types of objects defined below:
The following characters have the following special meaning in the format string:
The notation for spaces allows some flexibility for application output. Note that an empty character position in format represents one or more blank characters on the output (not white space, which can include newline characters). Therefore, another utility that reads that output as its input must be prepared to parse the data using scanf(3S) , awk(1) , and so forth. The *D character is used when exactly one space character is output.
Escape | Represents | Terminal Action |
Sequence | Character | |
\\ | backslash | None. |
\a | alert | Attempts to alert the user through audible or visible notification. |
\b | backspace | Moves the printing position to one column before the current position, unless the current position is the start of a line. |
\f | form-feed | Moves the printing position to the initial printing position of the next logical page. |
\n | newline | Moves the printing position to the start of the next line. |
\r | carriage-return | Moves the printing position to the start of the current line. |
\t | tab | Moves the printing position to the next tab position on the current line. If there are no more tab positions left on the line, the behaviour is undefined. |
\v | vertical-tab | Moves the printing position to the start of the next vertical tab position. If there are no more vertical tab positions left on the page, the behaviour is undefined. |
Each conversion character results in fetching zero or more arguments. The results are undefined if there are insufficient arguments for the format. If the format is exhausted while arguments remain, the excess arguments are ignored.
The conversion characters and their meanings are:
The treatment of integers and spaces is different from the printf(3S) function in that they can be surrounded with blank characters. This was done so that, given a format such as:
"%d\n",<foo>
the implementation could use a printf() call such as:
printf("%6d\n", foo);and still conform. This notation is thus somewhat like scanf() in addition to printf().
In no case does a non-existent or insufficient field width cause truncation of a field; if the result of a conversion is wider than the field width, the field is simply expanded to contain the conversion result. The term field width should not be confused with the term precision used in the description of %s.
One difference from the C function printf() is that the l and h conversion characters are not used. There is no differentiation between decimal values for type int, type long, or type short. The specifications %d or %i should be interpreted as an arbitrary length sequence of digits. Also, no distinction is made between single precision and double precision numbers (float or double in C). These are simply referred to as floating point numbers.
Many of the output descriptions use the term line, such as:
"%s", <input line>
Since the definition of line includes the trailing newline character already, there is no need to include a \n in the format; a double newline character would otherwise result.
"%s,*D %s*D %d,*D %d:%.2d\n",<weekday>,<month>,<day>,<hour>,<min>
To show *p written to 5 decimal places:
"pi*D =*D %.5f\n",<value of *p>
To show an input file format consisting of five colon-separated fields:
"%s:%s:%s:%s:%s\n",<arg1>,<arg2>,<arg3>,<arg4>,<arg5>