title: Nested for loop comparing files
body: <p>I am trying to write a bash script that looks at two files with the same name, each in a different directory.</p>
  
  <p>I know this can be done with diff -r, however, I would like to take everything that is in the second file that is not in the first file and output it into an new file (also with the same file name)</p>
  
  <p>I have written a (nested) loop with a grep command but it's not good and gives back a syntax error:</p>
  
  <pre><code>#!/bin/bash
  FILES=/Path/dir1/*
  FILES2=/Path/dir2/*
  
  for f in $FILES
  do
  for i in $FILES2
  do 
  if $f = $i
  grep -vf $i $f &gt; /Path/dir3/$i
  
  done
  done
  </code></pre>
  
  <p>Any help much appreciated. </p>