Question

I'm trying to run a bat file that will compare 1 file to another and output the differences

I've tried using gnu diff utilites, fc, and endless googleing to find a solution but I cant seem to figure it out

File 1

C:\Books\Tolkien, J.R.R. - The Adventures Of Tom Bombadil.pdf
C:\Books\test.rtf.epub
C:\Books\w_E_20130215.epub

File 2

C:\Books\test.rtf.epub
C:\Books\w_E_20130215.epub

I want file 3 to be

C:\Books\Tolkien, J.R.R. - The Adventures Of Tom Bombadil.pdf

Any one have any ideas?

Was it helpful?

Solution

You could use diff from the DiffUtils and something like this:

diff file1.txt file2.txt | findstr /r /c:"^<" /c:"^>" >file3.txt

The output lines will be preceded by < or >, depending on which file the respective line was missing in. If you want to remove those indicators as well, use something like this:

for /f "tokens=1*" %a in (
  'diff file1.txt file2.txt ^| findstr /r /c:"^<" /c:"^>"'
) do @echo %b >>file3.txt

Change %a and %b into %%a and %%b if you want to run this in a batch file.

OTHER TIPS

FINDSTR /v /b /e /l /g:file2. file1. >file3.

should produce the required results - lines in file1 missing from file2.

/v says 'not found', /b /e forces exact match - not part-of-line-matches /l literal.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top