How to modify bash printf output?

A format specification can also include modifiers that can control how much of the item’s value is printed, as well as how much space it gets. The modifiers come between the ‘%’ and the format-control letter. Here are the possible modifiers, in the order in which they may appear.

N$An integer constant followed by a ‘$’ is a positional specifier.
The minus sign, used before the width modifier, says to left-justify the argument within its specified width. Normally, the argument is printed right-justified in the specified width.
spaceFor numeric conversions, prefix positive values with a space and negative values with a minus sign.
+The plus sign, used before the width modifier, says to always supply a sign for numeric conversions, even if the data to format is positive. The ‘+’ overrides the space modifier.
#Use an “alternative form” for certain control letters. For ‘%o’, supply a leading zero. For ‘%x’ and ‘%X’, supply a leading ‘0x’ or ‘0X’ for a nonzero result. For ‘%e’, ‘%E’, ‘%f’, and ‘%F’, the result always contains a decimal point. For ‘%g’ and ‘%G’, trailing zeros are not removed from the result.
0A leading ‘0’ (zero) acts as a flag indicating that output should be padded with zeros instead of spaces. This applies only to the numeric output formats. This flag only has an effect when the field width is wider than the value to print.
A single quote or apostrophe character is a POSIX extension to ISO C. It indicates that the integer part of a floating-point value, or the entire part of an integer decimal value, should have a thousands-separator character in it. This only works in locales that support such characters.

Leave a Reply