我旁邊AWK oneliner:AWK:CONCAT字符串在字典價值數
{dict[$2"@"$6]=($(NF-2)/($(NF-2)+$NF))*100 } END {for (a in dict) { printf "%s %d :" , a, int(dict[a]) }}
我需要什麼,是添加到
($(NF-2)/($(NF-2)+$NF))*100 " out of" $(NF-2)+$NF
所以我想每個字典組合鍵的值awk計算所有數學,然後編寫字符串並將其作爲字典值。我已經嘗試過一些空格和括號的組合,但仍然沒有運氣。
瓦爾從輸入流填充:
$2 - host , not unique in input stream
$3 - partition , not unique in input stream
$NF - space avail
$NF-2 - space used
$(NF-2)+$NF - gives you overall capacity of partiton
輸出是
80% [email protected]/local/1
輸出預期:
80% [email protected]/local/1 out of 112G
------------- ---------解決方案-----------------------------------
下面有很好的接觸,我解決了這個問題。問題是我在printf部分中執行了int(),即截斷了輸出。儘管如此,我進一步遇到了其他問題,因此我的最終代碼與我預期的不同,它會提出問題。
'{key=($2 "@" $6 " out of " int((($(NF-2)+$NF)/1000)/1000) "GB") ; dict[key]=($(NF-2)/($(NF-2)+$NF))*100 } END {for (a in dict) { printf "%s , %d :" , a, int(dict[a]) }}'
I`ve移動「出」部分辭典鍵和能力,因爲字典值不能在我的情況的字符串,futher我將它與INT進行比較。
我已經添加了詳細信息,但它們在我的問題範圍內的重要性不高。問題是,如何將數學結果(字符串+數學結果)連接到字典中。我開始認爲awk有這個問題。 – 2012-08-01 18:31:05