 <p>Here's one way using <code>GNU awk</code>:</p> <pre><code>awk -F "[()]" 'FNR==NR { a[$(NF-1)]++; next } !(gensub(/(.*),.*/,"\\1","g",$(NF-1)) in a)' File1 File2 </code></pre> <p>Results:</p> <pre><code>INSERT INTO Queue (course,student,registrationDate) VALUES ('BKE974','3421728825','1368144500'); INSERT INTO Queue (course,student,registrationDate) VALUES ('DQY359','7421758823','1375874278'); </code></pre>