printf
From NetBSD Wiki
The printf(1) tool uses a format string to decide how to print the remaining arguments.
The % character introduces a format specifier. It is optionally followed by flag and a field width specifier. The following conversion specifier tells what data type is expected and how to display it.
Numbers
These are some conversion specifiers used for numbers:
| Specifier | Data type | Presentation |
|---|---|---|
| d | integer | decimal |
| o | integer | octal |
| x | integer | hexadecimal |
The field width specifier tells how many columns to be used for the number. The 0 flag specifies that the number should be padded with '0' characters. Default is ' ' (space).
Example:
$ printf "The number: %d\n" 11 The number: 11 $ printf "%4d\n" 11 11 $ printf "%04d\n" 11 0011 $ printf "%o\n" 11 13 $ printf "%x\n" 11 b
