Operating System - HP-UX
1850389 Members
2326 Online
104054 Solutions
New Discussion

Re: Update awk function to show Gigabytes only

 
BladeR1
New Member

Update awk function to show Gigabytes only

Hello,

Can please someone help me to update the function:

 

awk '
function human(x) {
    s="kMGTEPYZ";
    while (x>=1000 && length(s)>1)
        {x/=1024; s=substr(s,2)}
    return int(x+0.5) substr(s,1,1)
}
{gsub(/^[0-9]+/, human($1)); print}'

 

To show gigabytes only ?

Currently it shows like this:

2k

5M

3G

 

Instead I would like to see 3.000 0.0002 or so.

 

Thanks in advance!

1 REPLY 1
ranganath ramachandra
Esteemed Contributor

Re: Update awk function to show Gigabytes only


@BladeR1 wrote:

Can please someone help me to update the function:

Instead I would like to see 3.000 0.0002 or so.


Your requirement is way simpler than what that code is providing, so you could as well start afresh.

human(numBytes) { return sprintf "%f", numBytes / 2^30 ; }

 

 

 
--
ranga
hp-ux 11i v3[i work for hpe]

Accept or Kudo