title: Count number of nonempty entries in each column of, e.g., comm output
body: <p>The Unix command <code>comm file1 file2</code> has a 3 column output with lines unique to file1 in the first column, lines unique to file2 in the second, and lines shared by both in the 3rd (assuming file1 and file2 are sorted). It ends up looking something like this:</p>
  
  <pre><code>$ echo -e "alpha\nbravo\ncharlie" &gt; file1
  $ echo -e "alpha\nbravo\ndelta" &gt; file2
  $ comm file1 file2
                  alpha
                  bravo
  charlie
          delta
  </code></pre>
  
  <p>If I want the number of nonempty lines in each column, is there a general way to parse the output of <code>comm</code> and count those?</p>
  
  <p>I know that for <code>comm</code> in particular I could just run</p>
  
  <pre><code>for i in {12,23,31}; do comm -$i file1 file2 | wc -l; done
  </code></pre>
  
  <p>but I'm curious about solutions that take the <code>comm</code> output file as a starting point, for the sake of getting better at Unix command line. I added the <a href="/questions/tagged/awk" class="post-tag" title="show questions tagged &#39;awk&#39;" rel="tag">awk</a> tag because I have a hunch there's a good awk solution.</p>