title: Sorting array in shell using awk
body: <p>I need to sort this file in descending order avoiding duplicates</p>
  
  <pre><code>Bob 5 404
  Mike 3 404
  Bob 19 404
  Bob 78 404
  Mike 93 404
  Joe 7 404
  </code></pre>
  
  <p>So my result should be</p>
  
  <pre><code>Bob 102
  Mike 96
  Joe 7
  </code></pre>
  
  <p>What I have now is this</p>
  
  <pre><code>awk '{if($3 == 404) arr[$1]+=$2}END{for(i in arr)print i, arr[i]}' file
  </code></pre>
  
  <p>I know that there are <code>sort -d</code> but how I need to use it in awk?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <pre><code>awk 'BEGIN{FS=" "}{if($9 == 404) arr[$1]+=1}END{for(i in arr) print arr[i] | sort -k2nr }' input &gt; output
  </code></pre>
  
  <p>I get this result</p>
  
  <pre><code>sh: 0:  not found
  </code></pre>
  
  <p>And my output file is now empty.</p>