中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-10 14:58
47,811 topics / 349,897 posts / today 0 new / 48,255 members
DOS批处理 & 脚本技术(批处理室) » [Closed] How to judge the differences between two files and output to a file
Printable Version  2,190 / 9
Floor1 luckboy45 Posted 2007-05-26 21:18
中级用户 Posts 212 Credits 487
I searched through all the posts to find content about comparing the differences between two files and outputting the result, but I couldn't find the needed content at all. In desperation, I can only post.

The idea is like this: I want to compare the differences between two files 1.TXT and 2.TXT and output the result to 3.TXT

I have code for comparing differences, but it doesn't seem to work effectively; it can only compare one difference!

The code is as follows:
@echo off
:: Extract the differences between the two files to a certain file
:: code by jm 2006-9-9 CMD@XP
cd.>3.txt
for /f "tokens=1* delims=:" %%i in ('findstr /n. 1.txt') do (
for /f "tokens=1* delims=:" %%x in ('findstr /n. 2.txt') do (
if %%i equ %%x if not "%%j"=="%%y" (>>3.txt echo 1:%%j&>>3.txt echo 2:%%y&>>3.txt echo.)
)
)


I don't understand this code very well. Please help experts write a simple one. I remember that there was a master who wrote a simple one, but I can't find it! Please everyone. This problem has puzzled me for a long time..........


─────────────────── Moderation Record ────────────────────
Performer: lxmxn
Operation: Modify topic title
─────────────────── Moderation Record ────────────────────




The problem has been completely solved. Special thanks to the enthusiastic friends of the DOS Union for their warm help!


[ Last edited by luckboy45 on 2007-5-30 at 06:56 PM ]
Floor2 ieutk Posted 2007-05-27 02:45
初级用户 Posts 48 Credits 107
Floor3 qingfushuan Posted 2007-05-27 11:05
高级用户 Posts 327 Credits 502
Modified on the basis of jm

@echo off
:: Compare the differences between two text files and write to 3.txt**
::code by qingfushuan 2007-05-28 cmd@xp
for /f %%i in ('findstr . 1.txt') do (
find "%%i" 2.txt || echo 1:%%i >>3.txt
)
for /f %%x in ('findstr . 2.txt') do (
find "%%x" 1.txt || echo 2:%%x >>3.txt
)
Floor4 luckboy45 Posted 2007-05-27 19:56
中级用户 Posts 212 Credits 487
Thank you very much for everyone's help, I have written it out! Especially thank you all!~
Floor5 lp1129 Posted 2007-05-28 08:14
初级用户 Posts 92 Credits 186
The best comparison method that can display line numbers.
fc /u /n 1.txt 2.txt >3.txt
Floor6 qingfushuan Posted 2007-05-28 09:30
高级用户 Posts 327 Credits 502
Try using fc to compare the following files for differences. For example:

1.txt
C:\temp\~DFDE1F.tmp
C:\temp\~DFE7DC.tmp
C:\temp\T30DebugLogFile.txt
C:\temp\~DF3B23.tmp
C:\temp\qmf
C:\temp\~DFD28B.tmp
C:\temp\np28.tmp
C:\temp\cch~6e99008c.htp

2.txt
C:\temp\~DFDE1F.tmp
C:\temp\cch~6e99008c.htp
C:\temp\~DFE7DC.tmp
C:\temp\T30DebugLogFile.txt
C:\temp\~DF3B23.tmp
C:\temp\qmf
C:\temp\~DFD28B.tmp
C:\temp\np28.tmp
C:\temp\cch~6e99008c.htp
Floor7 luckboy45 Posted 2007-05-30 18:06
中级用户 Posts 212 Credits 487
I'm really grateful for everyone's enthusiastic help, and I've already made it.

Currently, I've successfully made a batch processing tool to detect and remove DLL trojans. If you want to have a try, please leave your QQ in the blog under my signature! ~ Thanks to all the friends in the DOS Union, I've learned a lot from here! Hehe! ~
Floor8 sxhzx Posted 2009-06-08 17:10
新手上路 Posts 6 Credits 6
@echo off
echo\Processing, please wait...&type nul>comp.txt
for /f %%a in ('type b.txt') do call :lp %%a
start comp.txt&goto :eof

:lp
for /f %%b in ('type cop.txt') do if %%b==%1 (goto :eof)
echo\%1>>comp.txt
Floor9 tempuser Posted 2009-06-08 20:37
高级用户 Posts 261 Credits 547
You did actual testing on this, but couldn't compare? Why? The output file 3.txt from qingfushuan's comparison result didn't appear?
Floor10 Hanyeguxing Posted 2009-06-09 03:37
银牌会员 Posts 897 Credits 1,039 From 在地狱中仰望天堂
I usually compare by first using sort to sort...
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023