As of v. 8.21
, coreutils
includes numfmt
:
numfmt
reads numbers in various representations and reformats them as requested.
The most common usage is converting numbers to / from human representation.
e.g.
printf %s\\n 5607598768908 | numfmt --to=iec-i
5.2Ti
Various other examples (including filtering, input/output processing etc) are presented HERE.
In addition, as of coreutils
v. 8.24
, numfmt
can process multiple fields with field range specifications similar to cut
, and supports setting the output precision with the --format
option
e.g.
numfmt --to=iec-i --field=2,4 --format='%.3f' <<<'tx: 180000 rx: 2000000'
tx: 175.782Ki rx: 1.908Mi