中国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 15:56
47,811 topics / 349,897 posts / today 0 new / 48,255 members
DOS批处理 & 脚本技术(批处理室) » How to compare the differences between two text contents
Printable Version  2,898 / 11
Floor1 hhh246 Posted 2006-08-31 02:07
初级用户 Posts 31 Credits 74
If the content in 1.txt is the same as that in 2.txt, replace it with blank.

1.txt
c:\windows
c:\windows\12.txt

2.txt
c:\windows
c:\windows\21.txt
c:\windows\123.txt
c:\my doc

The output is 3.txt
c:\windows\123.txt
c:\my doc

[ Last edited by namejm on 2007-2-5 at 10:24 AM ]
Floor2 namejm Posted 2006-08-31 02:38
荣誉版主 Posts 1,737 Credits 5,226 From 成都
There was a similar discussion post before, but I can't find it at once. So I simply post the previously sent complete code for your reference:
Floor3 namejm Posted 2006-08-31 02:45
荣誉版主 Posts 1,737 Credits 5,226 From 成都
Considering that you are a newbie and it's hard for you to understand the complete code in building 2, here is a code customized for you:
Floor4 namejm Posted 2006-08-31 08:32
荣誉版主 Posts 1,737 Credits 5,226 From 成都
Today I had nothing to do, so I pulled out the code from the third floor to play with. The result surprised me a lot: the content of 3.txt is

instead of what the original poster said
.

Oh my god, I'm having another setback. Alas, the original posters are really hard to deal with now.
Floor5 hhh246 Posted 2006-08-31 15:36
初级用户 Posts 31 Credits 74
Thanks everyone, but I tried this method and some can't be replaced. For example, the last name is LNK,

for /f "delims==" %%i in (1.txt) do findstr /l /i /x "%%i" "2.txt" ||if %errorlevel% == 0 echo %%i >>3.txt
Floor6 vkill Posted 2006-08-31 15:39
金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽
>>3.txt echo %%i

The one above can also be written in reverse, why?
Floor7 hhh246 Posted 2006-09-04 13:09
初级用户 Posts 31 Credits 74
So far, no one has been able to solve it.
Floor8 namejm Posted 2006-09-04 13:31
荣誉版主 Posts 1,737 Credits 5,226 From 成都
Originally posted by hhh246 at 2006-9-4 13:09:
There is still no one who can solve it yet,


  Really?

  Have you tested the above code by yourself? Can you ensure that there are no errors in your statement in the top post?
Floor9 hhh246 Posted 2006-09-08 08:52
初级用户 Posts 31 Credits 74
for /f "delims==" %%i in (1.log) do (
find /i "%%i" "2.log" || echo %%i>>b.txt
)

It works, but it's quite slow. Can anyone write a multi-threaded one?
Floor10 namejm Posted 2006-09-08 11:24
荣誉版主 Posts 1,737 Credits 5,226 From 成都
Originally posted by hhh246 at 2006-9-8 08:52:
for /f "delims==" %%i in (1.log) do (
find /i "%%i" "2.log" || echo %%i>>b.txt
)

It works, but the speed is quite slow. Can anyone write a multithreaded one?


  Is the speed slow? Unless you are dealing with tens of thousands of lines of text.

  Multithreaded? Hehe, CMD is in single-task mode, so it's impossible to implement multithreading.

[ Last edited by namejm on 2006-9-8 at 11:26 ]
Floor11 3742668 Posted 2006-09-11 00:08
荣誉版主 Posts 718 Credits 2,013
Floor12 namejm Posted 2006-09-18 21:19
荣誉版主 Posts 1,737 Credits 5,226 From 成都
The code of moderator 3742668 is extremely concise and efficient, PF.
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023