title: How to remove common lines between two files without sorting?
body: <p>I have two files not sortered which have some lines in common.</p>
  
  <p>file1.txt</p>
  
  <pre><code>Z
  B
  A
  H
  L
  </code></pre>
  
  <p>file2.txt</p>
  
  <pre><code>S
  L
  W
  Q
  A
  </code></pre>
  
  <p>The way I'm using to remove common lines is the following:</p>
  
  <pre><code>sort -u file1.txt &gt; file1_sorted.txt
  sort -u file2.txt &gt; file2_sorted.txt
  
  comm -23 file1_sorted.txt file2_sorted.txt &gt; file_final.txt
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>B
  H
  Z
  </code></pre>
  
  <p>The problem is that I want to keep the order of file1.txt, I mean:</p>
  
  <p>Desired output:</p>
  
  <pre><code>Z
  B
  H
  </code></pre>
  
  <p>One solution I tought is doing a loop to read all the lines of file2.txt and:</p>
  
  <pre><code>sed -i '/^${line_file2}$/d' file1.txt
  </code></pre>
  
  <p>But if files are big the performance may suck.</p>
  
  <ul>
  <li>Do you like my idea?</li>
  <li>Do you have any alternative to do it? </li>
  </ul>