BASH printf numbers with 1 char suffix -
i'm trying format number in bash. i'd replicate byte/packet number output iptables.
here examples:
258 591k 55273 37g 22244 2212 6127k 12m 114k
as can see:
- there no thousands separator,
- the field max of 5 characters wide,
- each suffix either: none, k, m, g, etc...
i've searched documentation on printf have been unable find can format number way. know how this?
thanks.
you build custom formatting awk
, :
awk 'begin{ u[0]=""; u[1]="k"; u[2]="m"; u[3]="g"} { n = $1; = 0; while(n > 1000) { i+=1; n= int(n/1000) } print n u[i] } '
input sample :
258 591000 55273 37000000000 22244 2212 6127000 12000000 114000
output :
258 591k 55k 37g 22k 2k 6m 12m 114k
Comments
Post a Comment