title: awk - Find the top url based on 4xx error code
body: <p>This is a follow up question from the one I posted yesterday that was answered: </p>
  
  <p><a href="https://stackoverflow.com/questions/47213752/awk-find-the-top-url-based-on-error-code/47228876#47228876">awk - Find the top url based on error code</a></p>
  
  <p>I used yesterdays answer and modified it from grabbing just 404 error codes, to now grabbing all 4xx.</p>
  
  <pre><code>awk '$3 ~ /^4/{a[$2]++}END{for(url in a){print a[url], url}}' samplelog.txt | sort -rn
  </code></pre>
  
  <p>This does work, but now I am wanting a more granular output. Right now it groups all 4xx together, for example a 403 and 404 will be counted as 2, not uniquely. I want to be able to count all 4xx, but then separate them by their unique codes. </p>
  
  <p>Sample Log:</p>
  
  <pre><code>GET /foo 404
  GET /foo 200
  GET /foo 404
  GET /foo 404
  GET /foo 400
  GET /foo 403
  GET /foo 403
  GET /bar 200
  GET /bar 400
  GET /foobar 404
  GET /foobar 200
  GET /foobar 404
  GET /foobar 403
  </code></pre>
  
  <p>Result with current script (same as above)</p>
  
  <pre><code>awk '$3 ~ /^4/{a[$2]++}END{for(url in a){print a[url], url}}' samplelog.txt | sort -rn    
  
  6 /foo
  3 /foobar
  1 /bar
  </code></pre>
  
  <p>Desired Result</p>
  
  <pre><code>3 /foo 404
  2 /foo 403
  2 /foobar 404
  1 /foo 400
  1 /bar 400
  1 /foobar 403
  </code></pre>