UNIX in a Nutshell: System V Edition

UNIX in a Nutshell: System V EditionSearch this book
Previous: 11.9 Implementation LimitsChapter 11
The awk Programming Language
Next: III. Text Formatting
 

11.10 Alphabetical Summary of Functions and Commands

The following alphabetical list of keywords and functions includes all that are available in awk, nawk, and gawk. nawk includes all old awk functions and keywords, plus some additional ones (marked as {N}). gawk includes all nawk functions and keywords, plus some additional ones (marked as {G}). Items marked with {B} are available in the Bell Labs awk. Items that aren't marked with a symbol are available in all versions.

11.10.1 printf Formats

Format specifiers for printf and sprintf have the following form:

%[flag][width][.precision]letter

The control letter is required. The format conversion control letters are as follows.

CharacterDescription
cASCII character
dDecimal integer
iDecimal integer (added in POSIX)
eFloating-point format ([-]d.precisione[+-]dd)
EFloating-point format ([-]d.precisionE[+-]dd)
fFloating-point format ([-]ddd.precision)
ge or f conversion, whichever is shortest, with trailing zeros removed
GE or f conversion, whichever is shortest, with trailing zeros removed
oUnsigned octal value
sString
xUnsigned hexadecimal number; uses a-f for 10 to 15
XUnsigned hexadecimal number; uses A-F for 10 to 15
%Literal %

The optional flag is one of the following.

CharacterDescription
-

Left-justify the formatted value within the field.

space

Prefix positive values with a space and negative values with a minus.

+

Always prefix numeric values with a sign, even if the value is positive.

#

Use an alternate form: %o has a preceding 0; %x and %X are prefixed with 0x and 0X, respectively; %e, %E, and %f always have a decimal point in the result; and %g and %G do not have trailing zeros removed.

0

Pad output with zeros, not spaces. This happens only when the field width is wider than the converted result.

The optional width is the minimum number of characters to output. The result will be padded to this size if it is smaller. The 0 flag causes padding with zeros; otherwise, padding is with spaces.

The precision is optional. Its meaning varies by control letter, as shown in this table.

ConversionPrecision Means
%d, %i, %oThe minimum number of digits to print
%u, %x, %X
%e, %E, %fThe number of digits to the right of the decimal point
%g, %GThe maximum number of significant digits
%sThe maximum number of characters to print


Previous: 11.9 Implementation LimitsUNIX in a Nutshell: System V EditionNext: III. Text Formatting
11.9 Implementation LimitsBook IndexIII. Text Formatting

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System