home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam    

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.

Character Description
c ASCII character
d Decimal integer
i Decimal integer (added in POSIX)
e Floating-point format ([-]d .precision e [+-]dd )
E Floating-point format ([-]d .precision E [+-]dd )
f Floating-point format ([-]ddd .precision )
g e or f conversion, whichever is shortest, with trailing zeros removed
G E or f conversion, whichever is shortest, with trailing zeros removed
o Unsigned octal value
s String
x Unsigned hexadecimal number; uses a -f for 10 to 15
X Unsigned hexadecimal number; uses A -F for 10 to 15
% Literal %

The optional flag is one of the following.

Character Description

Left-justify the formatted value within the field.


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.


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.

Conversion Precision Means
%d , %i , %o The minimum number of digits to print
%u , %x , %X
%e , %E , %f The number of digits to the right of the decimal point
%g , %G The maximum number of significant digits
%s The maximum number of characters to print

Previous: 11.9 Implementation Limits UNIX in a Nutshell: System V Edition Next: III. Text Formatting
11.9 Implementation Limits Book Index III. 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