China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-10 13:08
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Closed] How to judge the differences between two files and output to a file View 2,188 Replies 9
Original Poster Posted 2007-05-26 21:18 ·  中国 江苏 无锡 宜兴市 电信
中级用户
★★
Credits 487
Posts 212
Joined 2007-04-01 08:22
19-year member
UID 83597
Gender Male
Status Offline
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 ]
Floor 2 Posted 2007-05-27 02:45 ·  中国 广东 东莞 电信
初级用户
Credits 107
Posts 48
Joined 2006-11-30 12:06
19-year member
UID 72174
Gender Male
Status Offline
fc 1.txt 2.txt>>3.txt
她希望我把粪土变黄金,我希望她视黄金如粪土!
Floor 3 Posted 2007-05-27 11:05 ·  中国 四川 绵阳 江油市 电信
高级用户
★★★
Credits 502
Posts 327
Joined 2006-12-30 06:01
19-year member
UID 74981
Gender Male
Status Offline
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
)
Floor 4 Posted 2007-05-27 19:56 ·  中国 江苏 无锡 电信
中级用户
★★
Credits 487
Posts 212
Joined 2007-04-01 08:22
19-year member
UID 83597
Gender Male
Status Offline
Thank you very much for everyone's help, I have written it out! Especially thank you all!~
Floor 5 Posted 2007-05-28 08:14 ·  中国 陕西 渭南 电信
初级用户
★★
Credits 186
Posts 92
Joined 2007-03-27 08:20
19-year member
UID 83047
Gender Male
Status Offline
The best comparison method that can display line numbers.
fc /u /n 1.txt 2.txt >3.txt
Floor 6 Posted 2007-05-28 09:30 ·  中国 四川 绵阳 江油市 电信
高级用户
★★★
Credits 502
Posts 327
Joined 2006-12-30 06:01
19-year member
UID 74981
Gender Male
Status Offline
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
Floor 7 Posted 2007-05-30 18:06 ·  中国 江苏 无锡 电信
中级用户
★★
Credits 487
Posts 212
Joined 2007-04-01 08:22
19-year member
UID 83597
Gender Male
Status Offline
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! ~
Floor 8 Posted 2009-06-08 17:10 ·  中国 广西 南宁 电信
新手上路
Credits 6
Posts 6
Joined 2008-12-25 22:28
17-year member
UID 134925
Gender Male
Status Offline
@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
Floor 9 Posted 2009-06-08 20:37 ·  中国 黑龙江 大庆 大庆中基石油通信建设有限公司
高级用户
★★
Credits 547
Posts 261
Joined 2006-04-15 16:50
20-year member
UID 53887
Status Offline
You did actual testing on this, but couldn't compare? Why? The output file 3.txt from qingfushuan's comparison result didn't appear?
Floor 10 Posted 2009-06-09 03:37 ·  中国 吉林 延边朝鲜族自治州 延吉市 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
I usually compare by first using sort to sort...
Forum Jump: