title: Comparing two files for duplicate strings using mac bash
body: <p>I am trying to go through two .txt files to find matches and only print unique lines. I have a list of numbers and names and a second list of only partial numbers.  </p>
  
  <p>The file formats are like this<br>
  5553239090,batman</p>
  
  <p>second file is only six numbers<br>
  555323  </p>
  
  <p>I want to make sure that I am only taking out the lines that match the first six numbers so if I had 239090 I would not want that to take out the line. So far what I have found that works is this  </p>
  
  <pre><code>while read line
  
  do
  echo $line
      while read line2
  
          do
  
              if [[ "${line:0:6}" != "$line2" ]]; then
  
                  echo $line &gt;&gt; uniqueList2.txt
                  echo ${line:0:6}
              fi
  
          done &lt; file2.txt
  
  done &lt; file1.txt  
  </code></pre>
  
  <p>for some reason though it is not taking out all of the matches only some of them. It seems like the it matches the numbers at the top of file2 the best and the further down the list the are the more likely it is to miss it.  </p>
  
  <p>Is there something I missed or a better way to do this?</p>