title: How to get the output from the comm command into 3 separate files?
body: <p>The question <a href="https://stackoverflow.com/questions/373810/unix-command-to-find-lines-common-in-two-files">Unix command to find lines common in two files</a> has an <a href="https://stackoverflow.com/a/373819">answer</a> suggesting the use of the <code>comm</code> command to do the task:</p>
  
  <pre><code>comm -12 1.sorted.txt 2.sorted.txt
  </code></pre>
  
  <p>This shows the lines common to the two files (the <code>-1</code> suppresses the lines that are only in the first file, and the <code>-2</code> suppresses the lines only in the second file, leaving just the lines common to both files as output).  As the file names suggest, the input files must be in sorted order.</p>
  
  <p>In a <a href="https://stackoverflow.com/questions/373810/unix-command-to-find-lines-common-in-two-files/373819?noredirect=1#comment79598402_373819">comment</a> to that question, <a href="https://stackoverflow.com/users/3932463/bapors">bapors</a> asks:</p>
  
  <blockquote>
    <p>How would one have the outputs in different files?</p>
  </blockquote>
  
  <p>Seeking clarification, I asked:</p>
  
  <blockquote>
    <p>If you want the lines only in File1 in one file, those only in File2 in another, and those in both in a third, then (provided that none of the lines in the files starts with a tab) you could use <code>sed</code> to split the output to three files.</p>
  </blockquote>
  
  <p>User bapors confirmed:</p>
  
  <blockquote>
    <p>It is exactly what I was asking. Would you show an example?</p>
  </blockquote>
  
  <p>The answer is relatively long-winded and would spoil the simplicity of the answer to the other question (drowning it out with lots of information), so I've asked the question separately here — and provided an answer too.</p>