|
hhh246
初级用户
 
积分 74
发帖 31
注册 2006-8-26
状态 离线
|
『楼 主』:
如何比较两个文本内容的差别
使用 LLM 解释/回答一下
假如 1.txt 内容 如果在2.txt 中有相同替换为空白
1.txt
c:\windows
c:\windows\12.txt
2.txt
c:\windows
c:\windows\21.txt
c:\windows\123.txt
c:\my doc
输出为 3.txt
c:\windows\123.txt
c:\my doc
Last edited by namejm on 2007-2-5 at 10:24 AM ]
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 ]
|
|
2006-8-31 02:07 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
以前有过类似的讨论帖子,一下子找不到了,干脆把以前发的完整代码发出来,你可以借鉴一下思路:
@echo off
:: 比较A文件夹和B文件夹下文件名的异同(A和B文件夹下均无子目录)
:: 如果有不同,A文件夹中不同的写入a.txt,B文件夹中不同的写入b.txt
:: 相同部分的文件名写入c.txt
cd.>a.txt
cd.>b.txt
cd.>c.txt
dir /a-d /b "A文件夹的路径">list_a.txt
dir /a-d /b "B文件夹的路径">list_b.txt
for /f "delims=" %%i in (list_a.txt) do (
find "%%i" list_b.txt>nul 2>nul && echo %%i>>c.txt || echo %%i>>a.txt
)
for /f "delims=" %%i in (list_b.txt) do (
find "%%i" list_a.txt>nul 2>nul || echo %%i>>b.txt
)
del /q list_a.txt>nul 2>nul
del /q list_b.txt>nul 2>nul
start a.txt
start b.txt
start c.txt
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:
@echo off
:: Compare the differences in file names between folder A and folder B (there are no sub - directories under both folder A and folder B)
:: If there are differences, write the different ones in folder A to a.txt and the different ones in folder B to b.txt, and write the same part of file names to c.txt
cd.>a.txt
cd.>b.txt
cd.>c.txt
dir /a-d /b "Path of folder A">list_a.txt
dir /a-d /b "Path of folder B">list_b.txt
for /f "delims=" %%i in (list_a.txt) do (
find "%%i" list_b.txt>nul 2>nul && echo %%i>>c.txt || echo %%i>>a.txt
)
for /f "delims=" %%i in (list_b.txt) do (
find "%%i" list_a.txt>nul 2>nul || echo %%i>>b.txt
)
del /q list_a.txt>nul 2>nul
del /q list_b.txt>nul 2>nul
start a.txt
start b.txt
start c.txt
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-8-31 02:38 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
考虑到你是新手,一下子难以理解2楼的完整代码,针对你这个问题,为你量身定做一段代码吧:
@echo off
cd.>3.txt
for /f "tokens=*" %%i in (2.txt) do (
find "%%i" 1.txt || >>3.txt echo %%i
)
start 3.txt
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:
@echo off
cd.>3.txt
for /f "tokens=*" %%i in (2.txt) do (
find "%%i" 1.txt || >>3.txt echo %%i
)
start 3.txt
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-8-31 02:45 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
今天闲着没事,把3楼的代码拉出来玩了一把,结果让我大吃一惊:3.txt的内容是 c:\windows\21.txt
c:\windows\123.txt
c:\my doc
而非楼主所说的 c:\windows\123.txt
c:\my doc
。
我的妈呀,又在阴沟里翻船了。唉,现在的楼主真难伺候呀。
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
c:\windows\21.txt
c:\windows\123.txt
c:\my doc
instead of what the original poster said
c:\windows\123.txt
c:\my doc
.
Oh my god, I'm having another setback. Alas, the original posters are really hard to deal with now.
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-8-31 08:32 |
|
|
hhh246
初级用户
 
积分 74
发帖 31
注册 2006-8-26
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
谢谢各位,但我试过用这种方法但有的不能完成替换的比如最后名是LNK,
for /f "delims==" %%i in (1.txt) do findstr /l /i /x "%%i" "2.txt" ||if %errorlevel% == 0 echo %%i >>3.txt
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
|
|
2006-8-31 15:36 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
>>3.txt echo %%i
楼上这个倒过来写也可以啊,为什么?
>>3.txt echo %%i
The one above can also be written in reverse, why?
|
|
2006-8-31 15:39 |
|
|
hhh246
初级用户
 
积分 74
发帖 31
注册 2006-8-26
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
目前还没有人能解决呀,
So far, no one has been able to solve it.
|
|
2006-9-4 13:09 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
Originally posted by hhh246 at 2006-9-4 13:09:
目前还没有人能解决呀,
真的吗?
你动手测试了上面的代码了吗?你能保证你在顶楼的表述没有错误吗?
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?
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-9-4 13:31 |
|
|
hhh246
初级用户
 
积分 74
发帖 31
注册 2006-8-26
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
for /f "delims==" %%i in (1.log) do (
find /i "%%i" "2.log" || echo %%i>>b.txt
)
可以了,但速度相当慢,谁能写出多线程的吗?
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?
|
|
2006-9-8 08:52 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
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
)
可以了,但速度相当慢,谁能写出多线程的吗?
速度慢吗?除非你处理的是上W行的文本。
多线程?呵呵,CMD是单任务模式的,不可能实现多线程。
Last edited by namejm on 2006-9-8 at 11:26 ]
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 ]
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-9-8 11:24 |
|
|
3742668
荣誉版主
      
积分 2013
发帖 718
注册 2006-2-18
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
findstr /v /x /g:1.txt 2.txt
findstr /v /x /g:1.txt 2.txt
|
|
2006-9-11 00:08 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
3742668 版主的代码极度简洁高效,PF。
The code of moderator 3742668 is extremely concise and efficient, PF.
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-9-18 21:19 |
|