2 .\" Copyright 1992, X/Open Company Limited All Rights Reserved Portions Copyright (c) 1995, Sun Microsystems, Inc. All Rights Reserved
3 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
4 .\" http://www.opengroup.org/bookstore/.
5 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
6 .\" This notice shall appear on any product containing this material.
7 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
8 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
9 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
10 .TH FORMATS 5 "Mar 28, 1995"
12 formats \- file format notation
16 Utility descriptions use a syntax to describe the data organization within
17 files\(emstdin, stdout, stderr, input files, and output files\(emwhen that
18 organization is not otherwise obvious. The syntax is similar to that used by
19 the \fBprintf\fR(3C) function. When used for stdin or input file
20 descriptions, this syntax describes the format that could have been used to
21 write the text to be read, not a format that could be used by the
22 \fBscanf\fR(3C) function to read the input file.
26 The description of an individual record is as follows:
30 "<\fBformat\fR>", [<\fIarg1\fR>, <\fIarg2\fR>, .\|.\|., <\fIargn\fR>]
36 The \fBformat\fR is a character string that contains three types of objects
41 \fB\fI\fR\fIcharacters\fR\fI\fR \fR
44 Characters that are not \fIescape sequences\fR or \fIconversion
45 specifications\fR, as described below, are copied to the output.
51 \fB\fI\fR\fIescape sequences\fR\fI\fR \fR
54 Represent non-graphic characters.
60 \fB\fI\fR\fIconversion specifications\fR\fI\fR \fR
63 Specifies the output format of each argument. (See below.)
68 The following characters have the following special meaning in the format
76 (An empty character position.) One or more blank characters.
85 Exactly one space character.
90 The notation for spaces allows some flexibility for application output. Note
91 that an empty character position in \fBformat\fR represents one or more blank
92 characters on the output (not \fIwhite space\fR, which can include newline
93 characters). Therefore, another utility that reads that output as its input
94 must be prepared to parse the data using \fBscanf\fR(3C), \fBawk\fR(1), and so
95 forth. The character is used when exactly one space character is output.
96 .SS "Escape Sequences"
99 The following table lists escape sequences and associated actions on display
100 devices capable of the action.
107 \fBSequence\fR \fBCharacter\fR \fBTerminal Action\fR
109 \fB\e\e\fR backslash None.
111 Attempts to alert the user through audible or visible notification.
113 \fB\eb\fR backspace T{
114 Moves the printing position to one column before the current position, unless the current position is the start of a line.
116 \fB\ef\fR form-feed T{
117 Moves the printing position to the initial printing position of the next logical page.
120 Moves the printing position to the start of the next line.
122 \fB\er\fR carriage-return T{
123 Moves the printing position to the start of the current line.
126 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 behavior is undefined.
128 \fB\ev\fR vertical-tab T{
129 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 behavior is undefined.
133 .SS "Conversion Specifications"
136 Each conversion specification is introduced by the percent-sign character (%).
137 After the character %, the following appear in sequence:
141 \fB\fI\fR\fIflags\fR\fI\fR \fR
144 Zero or more \fIflags\fR, in any order, that modify the meaning of the
145 conversion specification.
151 \fB\fI\fR\fIfield width\fR\fI\fR \fR
154 An optional string of decimal digits to specify a minimum \fIfield width\fR.
155 For an output field, if the converted value has fewer bytes than the field
156 width, it is padded on the left (or right, if the left-adjustment flag (\(mi),
157 described below, has been given to the field width).
163 \fB\fI\fR\fIprecision\fR\fI\fR \fR
166 Gives the minimum number of digits to appear for the d, o, i, u, x or X
167 conversions (the field is padded with leading zeros), the number of digits to
168 appear after the radix character for the e and f conversions, the maximum
169 number of significant digits for the g conversion; or the maximum number of
170 bytes to be written from a string in s conversion. The precision takes the form
171 of a period (.) followed by a decimal digit string; a null digit string is
178 \fB\fI\fR\fIconversion characters\fR\fI\fR \fR
181 A conversion character (see below) that indicates the type of conversion to be
188 The \fIflags\fR and their meanings are:
195 The result of the conversion is left-justified within the field.
204 The result of a signed conversion always begins with a sign (+ or \(mi).
213 If the first character of a signed conversion is not a sign, a space character
214 is prefixed to the result. This means that if the space character and + flags
215 both appear, the space character flag is ignored.
224 The value is to be converted to an alternative form. For c, d, i, u, and s
225 conversions, the behaviour is undefined. For o conversion, it increases the
226 precision to force the first digit of the result to be a zero. For x or X
227 conversion, a non-zero result has 0x or 0X prefixed to it, respectively. For e,
228 E, f, g, and G conversions, the result always contains a radix character, even
229 if no digits follow the radix character. For g and G conversions, trailing
230 zeros are not removed from the result as they usually are.
239 For d, i, o, u, x, X, e, E, f, g, and G conversions, leading zeros (following
240 any indication of sign or base) are used to pad to the field width; no space
241 padding is performed. If the 0 and \(mi flags both appear, the 0 flag is
242 ignored. For d, i, o, u, x and X conversions, if a precision is specified, the
243 0 flag is ignored. For other conversions, the behaviour is undefined.
246 .SS "Conversion Characters"
249 Each conversion character results in fetching zero or more arguments. The
250 results are undefined if there are insufficient arguments for the format. If
251 the format is exhausted while arguments remain, the excess arguments are
255 The \fIconversion characters\fR and their meanings are:
259 \fB\fId,i,o,u,x,X\fR \fR
262 The integer argument is written as signed decimal (d or i), unsigned octal (o),
263 unsigned decimal (u), or unsigned hexadecimal notation (x and X). The d and i
264 specifiers convert to signed decimal in the style \fB[\fR\(mi\fB]\fR\fIdddd\fR.
265 The x conversion uses the numbers and letters 0123456789abcdef and the X
266 conversion uses the numbers and letters 0123456789ABCDEF. The \fIprecision\fR
267 component of the argument specifies the minimum number of digits to appear. If
268 the value being converted can be represented in fewer digits than the specified
269 minimum, it is expanded with leading zeros. The default precision is 1. The
270 result of converting a zero value with a precision of 0 is no characters. If
271 both the field width and precision are omitted, the implementation may precede,
272 follow or precede and follow numeric arguments of types d, i and u with blank
273 characters; arguments of type o (octal) may be preceded with leading zeros.
275 The treatment of integers and spaces is different from the \fBprintf\fR(3C)
276 function in that they can be surrounded with blank characters. This was done so
277 that, given a format such as:
285 the implementation could use a \fBprintf()\fR call such as:
289 printf("%6d\en", \fIfoo\fR);
293 and still conform. This notation is thus somewhat like \fBscanf()\fR in
294 addition to \fBprintf(\|).\fR
303 The floating point number argument is written in decimal notation in the style
304 \fB[\fR\(mi\fB]\fR\fIddd\fR.\fIddd\fR, where the number of digits after the
305 radix character (shown here as a decimal point) is equal to the \fIprecision\fR
306 specification. The \fBLC_NUMERIC\fR locale category determines the radix
307 character to use in this format. If the \fIprecision\fR is omitted from the
308 argument, six digits are written after the radix character; if the
309 \fIprecision\fR is explicitly 0, no radix character appears.
318 The floating point number argument is written in the style
319 \fB[\fR\(mi\fB]\fR\fId\fR.\fIddd\fRe\(+-\fBdd\fR (the symbol \(+- indicates
320 either a plus or minus sign), where there is one digit before the radix
321 character (shown here as a decimal point) and the number of digits after it is
322 equal to the precision. The \fBLC_NUMERIC\fR locale category determines the
323 radix character to use in this format. When the precision is missing, six
324 digits are written after the radix character; if the precision is 0, no radix
325 character appears. The E conversion character produces a number with E instead
326 of e introducing the exponent. The exponent always contains at least two
327 digits. However, if the value to be written requires an exponent greater than
328 two digits, additional exponent digits are written as necessary.
337 The floating point number argument is written in style f or e (or in style E in
338 the case of a G conversion character), with the precision specifying the number
339 of significant digits. The style used depends on the value converted: style g
340 is used only if the exponent resulting from the conversion is less than \(mi4
341 or greater than or equal to the precision. Trailing zeros are removed from the
342 result. A radix character appears only if it is followed by a digit.
351 The integer argument is converted to an \fBunsigned char\fR and the resulting
361 The argument is taken to be a string and bytes from the string are written
362 until the end of the string or the number of bytes indicated by the
363 \fIprecision\fR specification of the argument is reached. If the precision is
364 omitted from the argument, it is taken to be infinite, so all bytes up to the
365 end of the string are written.
374 Write a % character; no argument is converted.
379 In no case does a non-existent or insufficient \fIfield width\fR cause
380 truncation of a field; if the result of a conversion is wider than the field
381 width, the field is simply expanded to contain the conversion result. The term
382 \fIfield width\fR should not be confused with the term \fIprecision\fR used in
383 the description of %s.
386 One difference from the C function \fBprintf()\fR is that the l and h
387 conversion characters are not used. There is no differentiation between decimal
388 values for type \fBint\fR, type \fBlong\fR, or type \fBshort\fR. The
389 specifications %d or %i should be interpreted as an arbitrary length sequence
390 of digits. Also, no distinction is made between single precision and double
391 precision numbers (\fBfloat\fR or \fBdouble\fR in C). These are simply
392 referred to as floating point numbers.
395 Many of the output descriptions use the term \fBline\fR, such as:
399 "%s", <\fIinput line\fR>
405 Since the definition of \fBline\fR includes the trailing newline character
406 already, there is no need to include a \fB\en\fR in the format; a double
407 newline character would otherwise result.
410 \fBExample 1 \fRTo represent the output of a program that prints a date and
411 time in the form Sunday, July 3, 10:02, where \fI<weekday>\fR and \fI<month>\fR
416 "%s,/\e%s/\e%d,/\e%d:%.2d\en",<\fIweekday\fR>,<\fImonth\fR>,<\fIday\fR>,<\fIhour\fR>,<\fImin\fR>
421 \fBExample 2 \fRTo show pi written to 5 decimal places:
425 "pi/\e=/\e%.5f\en",<\fIvalue of pi\fR>
430 \fBExample 3 \fRTo show an input file format consisting of five colon-separated
435 "%s:%s:%s:%s:%s\en",<\fIarg1\fR>,<\fIarg2\fR>,<\fIarg3\fR>,<\fIarg4\fR>,<\fIarg5\fR>
442 \fBawk\fR(1), \fBprintf\fR(1), \fBprintf\fR(3C), \fBscanf\fR(3C)