I am trying to compare two files (old.txt and new.txt), if any lines that are in new.txt are different then old.txt then output to a txt file. I don't want any lines from old.txt present in the new file.
New files are uploaded to c:\temp\download and once processed, are copied to c:\temp\download\archived.
The script I'm using below will find the latest file in c:\temp\download and compare it with the last modified file in c:\temp\download\archived, and outputs the differences to a txt file. It works for the most part but the problem I am facing is that the output (%latestD%) file also contains lines from the old.txt. It should be a one way compare, new vs old and the output should not contain lines from the old.txt.
Here is what I am looking to achieve:
OLD.txt
Jim 789
Jane 123
James 999
Lily 111
NEW.txt
Jim 123
Jane 123
James 123
OUTPUT.txt
Jim 123
James 123
set "fC=C:\temp\download"
set "latestC="
for /f "delims=" %%a in ('dir "%fC%" /b /od /a-d /tw 2^>nul') do set "latest=%%a" & set "latestC=%fC%\%%a"
set "fD=C:\temp\download\archived
set "latestD="
for /f "delims=" %%a in ('dir "%fD%" /b /od /a-d /tw 2^>nul') do set "latestD=%fD%\%%a"
if not defined latestC ( echo NO File in C & exit /b )
if not defined latestD ( echo NO File in D & exit /b )
for /f "tokens=1,*" %%a in (
'diff "%latestC%" "%latestD%" ^| findstr /r /c:"^<" /c:"^>"'
) do (
>> "C:\temp\%latest%" echo(%%b
)
Thank you!