title: how to subtract the two files in linux
body: <p>I have two files like below:</p>
  
  <p>file1</p>
  
  <pre><code>"Connect"    CONNECT_ID="12"
  "Connect"    CONNECT_ID="11"
  "Connect"    CONNECT_ID="122"
  "Connect"    CONNECT_ID="109"
  </code></pre>
  
  <p>file2</p>
  
  <pre><code>"Quit"    CONNECT_ID="12"
  "Quit"    CONNECT_ID="11"
  </code></pre>
  
  <p>The file contents are not exactly same but similar to above and the number of records are minimum 100,000.</p>
  
  <p>Now i want to get the result as show below into <strong>file1</strong> (means the final result should be there in file1)</p>
  
  <pre><code>"Connect"    CONNECT_ID="122"
  "Connect"    CONNECT_ID="109"
  </code></pre>
  
  <p>I have used a while loop something like below:</p>
  
  <pre><code>awk {'print $2'} file2 | sed "s/CONNECTION_ID=//g" &gt; sample.txt
  
  while read actual; do
  
      grep -w -v $actual file1 &gt; file1_tmp
      mv -f file1_tmp file1
  
  done &lt; sample.txt
  </code></pre>
  
  <p>Here I have adjusted my code according to example. So it may or may not work.</p>
  
  <p>My problem is the loop is repeating for more than 1 hour to complete the process.</p>
  
  <p>So can any one suggest me how to achieve the same with any other ways like using <code>diff</code> or <code>comm</code> or <code>sed</code> or <code>awk</code> or any other linux command which will run faster?</p>
  
  <p>Here mainly I want to eliminate this big typical <code>while</code> loop.</p>