Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

@don_crissti's first Answer is good, but can be even shorter using Here StringsHere Strings, e.g.

$ numfmt --to=iec-i <<< "12345" 13Ki $ numfmt --to=iec-i --suffix=B <<< "1234567" 1.2MiB 

or even

$ numfmt --from=iec-i --to=iec-i --suffix=B <<< "12345Ki" 13MiB 

if <<< is not available you can use e.g.

$ echo "1234567" | numfmt --to=iec-i --suffix=B 1.2MiB 

@don_crissti's first Answer is good, but can be even shorter using Here Strings, e.g.

$ numfmt --to=iec-i <<< "12345" 13Ki $ numfmt --to=iec-i --suffix=B <<< "1234567" 1.2MiB 

or even

$ numfmt --from=iec-i --to=iec-i --suffix=B <<< "12345Ki" 13MiB 

if <<< is not available you can use e.g.

$ echo "1234567" | numfmt --to=iec-i --suffix=B 1.2MiB 

@don_crissti's first Answer is good, but can be even shorter using Here Strings, e.g.

$ numfmt --to=iec-i <<< "12345" 13Ki $ numfmt --to=iec-i --suffix=B <<< "1234567" 1.2MiB 

or even

$ numfmt --from=iec-i --to=iec-i --suffix=B <<< "12345Ki" 13MiB 

if <<< is not available you can use e.g.

$ echo "1234567" | numfmt --to=iec-i --suffix=B 1.2MiB 
Source Link
craeckie
  • 116
  • 1
  • 3

@don_crissti's first Answer is good, but can be even shorter using Here Strings, e.g.

$ numfmt --to=iec-i <<< "12345" 13Ki $ numfmt --to=iec-i --suffix=B <<< "1234567" 1.2MiB 

or even

$ numfmt --from=iec-i --to=iec-i --suffix=B <<< "12345Ki" 13MiB 

if <<< is not available you can use e.g.

$ echo "1234567" | numfmt --to=iec-i --suffix=B 1.2MiB