Skip to content

Instantly share code, notes, and snippets.

@angelovangel
Last active February 12, 2020 20:56
Show Gist options
  • Save angelovangel/b92fa7c190458b558b7120e38fd18f3d to your computer and use it in GitHub Desktop.
Save angelovangel/b92fa7c190458b558b7120e38fd18f3d to your computer and use it in GitHub Desktop.
SI prefixes with printf

In ksh only (not in bash), this just works:

printf '%#d\n' 105000000
105M

Even this!!!

printf "%#d\n" 12e+12 1.2e+4 12e+6
12T
12k
12M

printf has to be called directly in ksh, but not as part of e.g. awk or as part of a pipe with xargs...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment