JSS
JSS

Reputation: 51

how do i compare two files using a batch script with a count of differences

I have two files file1 and file2.

File1 ( which is the reference file) contains

ABC
DEF
ABCD
XYZ
DEFG

File2 contains

ABC
DEF

If "File2" has more entries as compared to "File1" then display the count of such differences and the entries which are different

Upvotes: 0

Views: 1554

Answers (2)

Endoro
Endoro

Reputation: 37569

findstr /vxg:file2 file1>file3
for /f %%a in ('^<file3 find /v /c ""') do echo %%a differences

Upvotes: 2

foxidrive
foxidrive

Reputation: 41224

Input files are file1.txt and file2.txt and the result file is file3.tmp

Unsure that the files have trailing CRLF pairs.

@echo off
copy file2.txt file3.tmp >nul
for /f "delims=" %%a in (file1.txt) do (
findstr /v "^%%a$" <file3.tmp >file3.tmp3
move file3.tmp3 file3.tmp >nul
)
echo number of new lines:
find /c /v "" <file3.tmp
echo.
type file3.tmp
pause

Upvotes: 0

Related Questions