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-06 06:25
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] Compare the contents of two text files and output the differences View 1,188 Replies 7
Original Poster Posted 2007-10-17 14:09 ·  中国 广东 广州 番禺区 电信
初级用户
Credits 86
Posts 45
Joined 2007-07-26 17:35
19-year member
UID 94082
Gender Male
Status Offline
I want to compare the contents of two text files and output the different content from the two files.
First I used

findstr /v /g:1.txt 2.txt>3.txt
pause

and it said findstr: the search string is too long

Both files are around 450K or so, and most of the content is the same, hehe

Then I used

for /f %%a in (1.txt) do (
for /f %%b in (2.txt) do (
findstr /v /c:"%%a" "%%b">>3.txt
)
)
pause

There was no error message this time, but 3.txt is an empty file. So depressing.......

Please give me some guidance, experts
Floor 2 Posted 2007-10-17 17:04 ·  中国 香港 理工大学
新手上路
Credits 7
Posts 4
Joined 2007-10-13 23:05
18-year member
UID 99673
Gender Male
Status Offline
The fc command is specifically for comparing files

Maybe you can give it a try
Floor 3 Posted 2007-10-17 18:22 ·  中国 广东 广州 番禺区 电信
初级用户
Credits 86
Posts 45
Joined 2007-07-26 17:35
19-year member
UID 94082
Gender Male
Status Offline
The text output by this command doesn't meet my requirements.... there is a lot of extra information. I only want to output the different content in the two files, and I need to use that content for something else...... still asking the experts for advice........
Floor 4 Posted 2007-10-17 21:16 ·  中国 四川 泸州 联通
高级用户
★★★
Credits 609
Posts 374
Joined 2006-08-02 22:38
20-year member
UID 59720
Status Offline
Comparing two text files over 450k in size, if you use that method and it actually works, it might still take several hours. The more different lines there are, the longer it will take.
Floor 5 Posted 2007-10-18 01:54 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
A.txt

AAA
CCC
BBB


B.txt

BBB
AAA
CCC

Are the contents of a.txt and b.txt considered different or the same?
Floor 6 Posted 2007-10-18 12:45 ·  中国 广东 广州 天河区 电信
初级用户
Credits 86
Posts 45
Joined 2007-07-26 17:35
19-year member
UID 94082
Gender Male
Status Offline
Consider them the same. Moderator, please help, many thanks
Floor 7 Posted 2007-10-18 16:46 ·  中国 台湾 中华电信(HiNet)数据中心
初级用户
Credits 83
Posts 34
Joined 2007-10-14 13:49
18-year member
UID 99713
Gender Male
Status Offline
I couldn't solve it with DOS,
so later I wrote it in C. Anyone who knows, please leave a message, thanks.
Floor 8 Posted 2007-10-21 21:48 ·  中国 四川 泸州 联通
高级用户
★★★
Credits 609
Posts 374
Joined 2006-08-02 22:38
20-year member
UID 59720
Status Offline
To reduce runtime, my method is: use fc ---- delete duplicate lines ---- more +n, and the result is clean. Processing files around 450k generally takes a few dozen seconds.
Forum Jump: