Note that there are some explanatory texts on larger screens.

plurals
  1. POawk: concat string with number in dict value
    primarykey
    data
    text
    <p>I have next awk oneliner :</p> <pre><code>{dict[$2"@"$6]=($(NF-2)/($(NF-2)+$NF))*100 } END {for (a in dict) { printf "%s %d :" , a, int(dict[a]) }} </code></pre> <p>What i need, is to add to value of each dictionary key combination of </p> <pre><code>($(NF-2)/($(NF-2)+$NF))*100 " out of" $(NF-2)+$NF </code></pre> <p>So i want awk to calculate all math , then compose string and put it as dictionary value. I already tried with some combination of spaces and brackets but still no luck. </p> <p>Vars are filled from input stream :</p> <pre><code>$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 </code></pre> <p>Output is </p> <pre><code>80% host1@/local/1 </code></pre> <p>Output expected:</p> <pre><code>80% host1@/local/1 out of 112G </code></pre> <p>----------------------Solution-----------------------------------</p> <p>With good catch below , i resolved this. Issue was that i did int() in printf part, that truncated output. Though, further i faced other problems with my wrap-around shell part, therefore my final code was different than i expected it to be asking question.</p> <pre><code>'{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]) }}' </code></pre> <p>I`ve moved "out of " and capacity part to dictionary key , because dict value cannot be string in my case, futher i will compare it with INT.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload