find percentage - awk

Please help me with this ...

Input file

 
/vol/test1 10G 
/vol/test2      1G
/vol/test3      200G
/vol/test4 3G

Output File

/vol/test1 10G - - 9G -
/vol/test2      1024M - - 921M -
/vol/test3      200G - - 180G -
/vol/test4 3072M - - 2764M -

Basically if Column 2 ( which is in GB's) is less then 10 , convert into MB ( x 1024) and calculate its 90% value ( rounded off) and add it to column 5 , also change G's into M's ... for column 2 which is greater than 10 ... just calculate 90% of it and add it to column 5 as it is

Thanks

Try:

awk '{x=$2;sub("G$","",x)}x<10{printf ("%s %dM - - %dM -\n",$1,x*1024,x*1024*0.9)}x>=10{printf ("%s %dG - - %dG -\n",$1,x,x*0.9)}' file

Thanks Bartus ..but i get this output

 
/vol/test1 10G - - 9G -
/vol/test2 1024M - - 921M -
/vol/test3 200G - - 180G -
/vol/test4 3G - - 2G -

3G was not converted to MB as 3 < 10

Thanks

Post output of:

cat -ev file
/vol/test1 10G$
/vol/test2      1G$
/vol/test3      200G$
/vol/test4 3G$

Hmmm, I noticed some weird behavior of "nawk" in Solaris that seem to be what you are also encountering. To fix it try this:

awk '{x=$2;sub("G$","",x);x*=1}x<10{printf ("%s %dM - - %dM -\n",$1,x*1024,x*1024*0.9)}x>=10{printf ("%s %dG - - %dG -\n",$1,x,x*0.9)}' file

Nice ...Thanks ! I was testing it on Solaris ... it works now ....