必要86.1%
、EEDは少なくとも493.353
参照する取得するには:ここで
$ awk 'BEGIN{printf "%f\n", 86.1*573/100}'
493.353000
$ awk 'BEGIN{printf "%f\n", 493.353/573*100}'
86.100000
が修正ヘッダと割合
awk 'BEGIN{
OFS=FS=":";
h["Iie"]="Total Size";
h["Eed"]="Total Used";
h["vail"]="Avilable"
}
$1 in h{
sub(/T/," TB",$2);
print h[$1], $2;
h[$1]=$2
}
END{
print "Used (%)",h["Eed"]/h["Iie"]*100
}
' infile
を印刷する一つの方法です
入力:
$ cat infile
Iie:573T
Eed:448.0T
vail:74T
出力:
$ awk 'BEGIN{OFS=FS=":";h["Iie"]="Total Size";h["Eed"]="Total Used";h["vail"]="Avilable"}$1 in h{sub(/T/," TB",$2);print h[$1],$2; h[$1]=$2 }END{print "Used (%)",h["Eed"]/h["Iie"]*100}' infile
Total Size:573 TB
Total Used:448.0 TB
Avilable:74 TB
Used (%):78.185
説明
awk 'BEGIN{
OFS=FS=":"; # i/p and o/p field sep
h["Iie"]="Total Size"; # array of key and values
h["Eed"]="Total Used";
h["vail"]="Avilable"
}
$1 in h{ # if its of our interest and in array h
# not really necessary,
# in current context
# skips saving any unwanted column in array h
sub(/T/," TB",$2); # substiute T with space and TB
# can also be " &B"
print h[$1], $2; # print corresponding header and 2nd field
h[$1]=$2 # we are done save value
}
END{
# calculate percentage from saved value
#
print "Used (%)",h["Eed"]/h["Iie"]*100
}
' infile