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-12 13:24
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How can a batch file compare two text files and output the lines that are different? View 1,086 Replies 6
Original Poster Posted 2010-04-21 19:26 ·  中国 山西 太原 电信
新手上路
Credits 10
Posts 10
Joined 2010-01-21 01:30
16-year member
UID 159120
Gender Male
Status Offline
Requirement: for lines that exist in A.txt, search through B.txt line by line, and then output the ones not found to 结果.txt


Example:
Contents of a.txt
___________________________________
aaa
bbb
vwh
ddd
eee
...
Thousands more lines omitted below
____________________________________


Contents of b.txt
____________________________________
000
aaa
q23
FFF
ggg
sdd
jjk
yyu
eee
...
Thousands more lines omitted below
____________________________________

Requirement: for lines that exist in A.txt, search through B.txt line by line, and then output the ones not found to 结果.txt




[ Last edited by adslcool on 2010-4-21 at 19:44 ]
Floor 2 Posted 2010-04-21 19:27 ·  中国 山西 太原 电信
新手上路
Credits 10
Posts 10
Joined 2010-01-21 01:30
16-year member
UID 159120
Gender Male
Status Offline
I need it urgently, handling thousands of records is really too hard
Floor 3 Posted 2010-04-21 19:35 ·  中国 吉林 延边朝鲜族自治州 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
Floor 4 Posted 2010-04-21 19:39 ·  中国 山西 太原 电信
新手上路
Credits 10
Posts 10
Joined 2010-01-21 01:30
16-year member
UID 159120
Gender Male
Status Offline
Requirement: for lines that exist in A.txt, search through B.txt line by line, and then output the ones not found to 结果.txt
Floor 5 Posted 2010-04-21 19:46 ·  中国 山西 太原 电信
新手上路
Credits 10
Posts 10
Joined 2010-01-21 01:30
16-year member
UID 159120
Gender Male
Status Offline
Floor 6 Posted 2010-04-21 20:17 ·  中国 吉林 延边朝鲜族自治州 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
for /f "delims=" %%i in (a.txt) do set "%%i=="
for /f "delims=" %%i in (b.txt) do if not defined %%i >>c.txt echo.%%i

Using a.txt as the sample for comparison, if the same line does not exist in b.txt then output it to c.txt
Floor 7 Posted 2010-04-21 20:21 ·  中国 吉林 延边朝鲜族自治州 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
for /f "delims=" %%i in (a.txt) do set "%%i=="
for /f "delims=" %%i in (b.txt) do if defined %%i >>c.txt echo.%%i

Using a.txt as the sample for comparison, if the same line exists in b.txt then output it to c.txt
Forum Jump: