1753265 Members
5282 Online
108792 Solutions
New Discussion юеВ

Unix Script Help

 

Unix Script Help

Hi,

Need some help.

I use command as follow :-
bdf |grep /usr |awk '{print $(NF-2)/1024/1024,$(NF-1),$NF}'

will give me the following output :

23103823 53% /usr.

How could I change the 23103823 in Kb to Gb and the output should be in integer (discard the floating).

The expected output should be :-

22 53% /usr


Thanks
4 REPLIES 4
James R. Ferguson
Acclaimed Contributor

Re: Unix Script Help

Hi:

# bdf |grep /usr |awk '{printf {printf "%4.2f\n", $(NF-2)/1024/1024,$(NF-1),$NF}'

...and you asked for an integer but what you seem to want is a 2-decimal real number as above.

Regards!

...JRF...
Pete Randall
Outstanding Contributor

Re: Unix Script Help

Glenn S. Davidson
Trusted Contributor

Re: Unix Script Help

I would use the int function:

bdf |grep /usr |awk '{print int($(NF-2)/1024/1024),$(NF-1),$NF}'

There will be no decimals or anything and it will not round up. It just strips the decimal and what is after it away.
Conformity Destroys a mans initiative and independence. It supresses his powerful inner drive to do his own thing.
Sandman!
Honored Contributor

Re: Unix Script Help

# bdf /usr |awk '{print $(NF-2)/(1024^2),$(NF-1),$NF}'

~cheers