title: Counting with a complicated conditions using awk
body: <p>I have a task. I must count inner and outer water bridges from data. I want to show you how I should count them.</p>
  
  <p>For example, I have a data file:</p>
  
  <pre><code>MGD12   SOL54  
  MGD14   SOL74    
  MGD10   SOL37    
  MGD16   SOL65    
  MGD21   SOL66
  MGD2    SOL65    
  MGD64   SOL74    
  MGD10   SOL37    
  MGD72   SOL74    
  MGD12   SOL54
  </code></pre>
  
  <p>Inner water bridges are when: MGD and SOL are the same (duplicates). Outer water bridges are when: MGD is different, but SOL is the same.</p>
  
  <p>For example, in the third column, I write which line is inner water bridge and which is outer</p>
  
  <pre><code>1.MGD12    SOL54    inner (the same in line 10)
  2.MGD14    SOL74    outer (the same SOL in 7, 9)
  3.MGD10    SOL37    inner (the same in line 8)
  4.MGD16    SOL65    outer (the same SOL in 6)
  5.MGD21    SOL66    no water bridge
  6.MGD2     SOL65    outer (the same SOL in 4)
  7.MGD64    SOL74    outer (the same SOL in 2, 9)
  8.MGD10    SOL37    inner (the same in line 3)
  9.MGD72    SOL74    outer (the same SOL in 2, 7)
  10.MGD12   SOL54    inner (the same in line 1)
  </code></pre>
  
  <p>In the output, I want just the number of inner and outer water bridges. In this case, it will be only numbers 4 and 5.</p>
  
  <pre><code>4 5
  </code></pre>
  
  <p>I try to write a script, but I don't know what I should put in condition, maybe I should use arrays?</p>
  
  <pre><code>#!/bin/bash
  awk '{ if () inner++; else if () outer++} END { print inner " " outer}' probe.txt
  </code></pre>
  
  <p>Edit, I try to use that script, but it's not working</p>
  
  <pre><code>#!/bin/bash
  awk 'NR==FNR         {a[$1,$2]++; s[$2]++; next} 
         a[$1,$2]!=s[$2] {outer++; next} 
         s[$2]!=1        {inner++} 
         END             {print inner,outer}' probe.txt | tee probe2.txt
  </code></pre>
  
  <p>input</p>
  
  <pre><code>MGD12   SOL54    
  MGD14   SOL74    
  MGD10   SOL37    
  MGD16   SOL65    
  MGD21   SOL66
  MGD2    SOL65    
  MGD64   SOL74    
  MGD10   SOL37    
  MGD72   SOL74    
  MGD12   SOL54
  </code></pre>
  
  <p>In output I have a empty line (probe2.txt)</p>
  
  <pre><code>
  </code></pre>
  
  <p>When I try another scipt</p>
  
  <pre><code>#!/bin/bash
  awk 'NR==FNR {a[$1,$2]++; s[$2]++; next} 
                 {print $0, (a[$1,$2]==s[$2]?(s[$2]==1?"no":"inner"):"outer")}' probe.txt | tee probe2.txt
  </code></pre>
  
  <p>I have again empty output.</p>