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 03:21
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Need to compare the contents of two text files? View 972 Replies 3
Original Poster Posted 2010-07-29 10:42 ·  中国 四川 泸州 电信
初级用户
Credits 54
Posts 27
Joined 2006-12-02 11:46
19-year member
UID 72370
Gender Male
Status Offline
Hello everyone! Please help take a look at how this should be written.
A.TXT contents
QQ Speed
QQ Island
QQ Fengshenji
QQ Huaxia
Baby Tank
Snowstorm Love Sky
...........

B.TXT contents
QQ Island
QQ Speed
Speed
Baby Tank
Baby

The contents of A.TXT are the standard. For each line in B.TXT, if it is different from A.TXT, find it and put it into C.TXT (for example, Speed and Baby)

[ Last edited by lbccyxs on 2010-7-29 at 10:51 ]
Floor 2 Posted 2010-07-30 12:49 ·  中国 广东 东莞 电信
新手上路
Credits 1
Posts 1
Joined 2010-07-28 15:14
16-year member
UID 171368
Gender Male
Status Offline
@echo off
:: Extract the differences between the two files into some file
::
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.)
)
)




------------------------
http://www.jb51.net/list/list_106_2.htm
Floor 3 Posted 2010-08-03 11:16 ·  中国 四川 泸州 电信
初级用户
Credits 54
Posts 27
Joined 2006-12-02 11:46
19-year member
UID 72370
Gender Male
Status Offline
This one is relatively slow (mainly because there are a lot of games), but it can meet the requirement. The purpose is to delete expired games.
cd.>c.bat
for /f "tokens=*" %%i in (a.txt) do (
find "%%i" b.txt || >>c.bat echo RD /S/Q K:\网络游戏\%%i)
del 1.txt&del a.txt&del b.txt
notepad c.bat

[ Last edited by lbccyxs on 2010-8-3 at 22:32 ]
Floor 4 Posted 2010-08-04 00:46 ·  美国 惠普HP
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
Wouldn't a single line of findstr do it?
Forum Jump: