FINDSTR by itself ought to be a great solution. Reading the documentation, one would think the following literal search should work.
findstr /vlxg:"temp2.txt" "temp1.txt" >temp.txt
But the following FINDSTR bugs and limitations prevent the above from being reliable
The solution is to do a regular expression search instead. But this requires that regular expression meta characters within temp2.txt must be escaped. This is a perfect task for my JREPL.BAT regular expression find/replace utility. JREPL.BAT is a hybrid JScript/batch script that runs natively on any Windows machine from XP onward.
jrepl "[.*^$[\\]" "\$&" /f "temp2.txt"|findstr /rvxg:/ "temp1.txt" >"temp.txt"
The above works as follows.
The JREPL command escapes meta characters within temp2.txt and the output is piped to FINDSTR
The FINDSTR /R option treats all search strings as regular expressions
The /V option causes matching lines to be suppressed, and non matching lines are printed
The /X option means a search string must match the entire line
The /G:/ option instructs FINDSTR to read the search strings from stdin (the pipe)
The JREPL | FINDSTR solution has the following limitations, all due to FINDSTR behavior
- All lines in temp2.txt must be <= 511 characters, even after the meta characters have been escaped
- All lines in temp1.txt must be terminated by \r\n (carriage return linefeed)
- \r must not appear anywhere within temp1.txt other than at the end of a line.
The limitations can be eliminated and the solution is much simpler if you download GNU grep for Windows - a port of the standard unix utility.
grep -x -v -F -f "temp2.txt" "temp1.txt" >"temp.txt"