numfmt
numfmt [OPTION]... [NOMBRE]...
Convertir les nombres vers/depuis des chaînes lisibles par l’homme
Options
--debug-
print warnings about invalid input
--grouping-
use locale-defined grouping of digits, for example 1,000,000 (which means it has no effect in the C/POSIX locale)
--delimiter=<X>,-d <X>-
use X instead of whitespace for field delimiter
--field=<FIELDS>-
replace the numbers in these input fields; see FIELDS below
--format=<FORMAT>-
use printf style floating-point FORMAT; see FORMAT below for details
--from=<UNIT>-
auto-scale input numbers to UNITs; see UNIT below
--from-unit=<N>-
specify the input unit size
--to=<UNIT>-
auto-scale output numbers to UNITs; see UNIT below
--to-unit=<N>-
the output unit size
--padding=<N>-
pad the output to N characters; positive N will right-align; negative N will left-align; padding is ignored if the output is wider than N; the default is to automatically pad if a whitespace is found
--header=<N>-
print (without converting) the first N header lines; N defaults to 1 if not specified
--round=<METHOD>-
use METHOD for rounding when scaling
--suffix=<SUFFIX>-
print SUFFIX after each formatted number, and accept inputs optionally ending with SUFFIX
--unit-separator=<STRING>-
use STRING to separate the number from any unit when printing; by default, no separator is used
--invalid=<INVALID>-
set the failure mode for invalid input
--zero-terminated,-z-
line delimiter is NUL, not newline
Options d’UNITÉ :
-
none : aucune mise à l’échelle automatique n’est effectuée ; les suffixes déclencheront une erreur
-
auto : accepter un suffixe optionnel d’une/deux lettres :
1K = 1000, 1Ki = 1024, 1M = 1000000, 1Mi = 1048576,
-
si : accepter un suffixe optionnel d’une lettre :
1K = 1000, 1M = 1000000, …
-
iec : accepter un suffixe optionnel d’une lettre :
1K = 1024, 1M = 1048576, …
-
iec-i : accepter un suffixe optionnel de deux lettres :
1Ki = 1024, 1Mi = 1048576, …
-
FIELDS supporte les plages de champs de style cut(1) :
N N-ième champ, compté à partir de 1 N- du N-ième champ jusqu’à la fin de la ligne N-M du N-ième au M-ième champ (inclus) -M du premier au M-ième champ (inclus)
- tous les champs
Plusieurs champs/plages peuvent être séparés par des virgules
FORMAT doit être adapté pour imprimer un argument à virgule flottante %f. Une guillemet optionnelle (%’f) activera –grouping (si pris en charge par la locale actuelle). Une valeur de largeur optionnelle (%10f) remplira la sortie. Un zéro optionnel (%010f) remplira le nombre de zéros. Des valeurs négatives optionnelles (%-10f) aligneront à gauche. Une précision optionnelle (%.1f) remplacera la précision déterminée par l’entrée.
Examples
Convert 1.5K (SI Units) to 1500:
numfmt --from si 1.5K
Convert 1500 to 1.5K (SI Units):
numfmt --to si 1500
Convert 1.5K (IEC Units) to 1536:
numfmt --from iec 1.5K
Use appropriate conversion based on the suffix:
numfmt --from auto {{1.5Ki}}
Convert 5th field (1-indexed) to IEC Units without converting header:
ls -l | numfmt --header=1 --field 5 --to iec
Convert to IEC units, pad with 5 characters, left aligned:
du {{[-s|--summarize]}} * | numfmt --to iec --format "%-5f"
The examples are provided by the tldr-pages project under the CC BY 4.0 License.
Please note that, as uutils is a work in progress, some examples might fail.