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.
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.precisione [+-]dd) |
E | Floating-point format ([-]d.precisionE [+-]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. |
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: |
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.
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 |