|
junyee
中级用户
  
积分 253
发帖 112
注册 2006-5-31
状态 离线
|
『楼 主』:
[求助]如何比较并输出两个文本的不同之处
使用 LLM 解释/回答一下
今有两个文件a.txt b.txt ,内容假设如下
----a.txt----(这句是注释)
1
2
3
4
5
----end----(这句也是注释,下同)
----b.txt----
1
b
3
4
5
6
----end----
如何通过批处理生成,
----a-b.txt----(a有但b没有的内容)
2
----end----
----b-a.txt----(b有但a没有的内容)
b
----end----
----a~b.txt----(a,b都有的内容)
1
3
4
5
6
----end----
请教各位坛友,P处理有没有可能实现这样的效果
我知道系统中有一个fc 可以比较文本,但他生成的结果不太直观
比较是以行为单位,可以使用外部命令.
Now there are two files a.txt and b.txt, and the contents are assumed as follows:
----a.txt----(This is a comment)
1
2
3
4
5
----end----(This is also a comment, the same below)
----b.txt----
1
b
3
4
5
6
----end----
How to generate through batch processing:
----a-b.txt----(Content that is in a but not in b)
2
----end----
----b-a.txt----(Content that is in b but not in a)
b
----end----
----a~b.txt----(Content that is in both a and b)
1
3
4
5
----end----
Asking all forum friends, is it possible to achieve such an effect with P processing? I know there is a fc command in the system that can compare text, but the generated result is not very intuitive.
Comparison is based on lines, and external commands can be used.
|
|
2009-11-25 15:53 |
|
|
ZJHJ
高级用户
   
积分 609
发帖 374
注册 2006-8-2
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
cd.>bh.txt
for /f "delims=" %%i in (a.txt) do SET %%i=A
for /f "delims=" %%j in (b.txt) do if /I not defined %%j echo %%j>>bh.txt
-------------------
cd.>bh.txt
for /f "delims=" %%i in (a.txt) do SET %%i=A
for /f "delims=" %%j in (b.txt) do if /I defined %%j echo %%j>>bh.txt
cd.>bh.txt
for /f "delims=" %%i in (a.txt) do SET %%i=A
for /f "delims=" %%j in (b.txt) do if /I not defined %%j echo %%j>>bh.txt
-------------------
cd.>bh.txt
for /f "delims=" %%i in (a.txt) do SET %%i=A
for /f "delims=" %%j in (b.txt) do if /I defined %%j echo %%j>>bh.txt
|
|
2009-11-25 21:43 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
root@~ > grep -xvfb.txt a.txt
2
root@~ > grep -xvfa.txt b.txt
b
root@~ > grep -xfa.txt b.txt
1
3
4
5
6
root@~ >
```
root@~ > grep -xvfb.txt a.txt
2
root@~ > grep -xvfa.txt b.txt
b
root@~ > grep -xfa.txt b.txt
1
3
4
5
6
root@~ >
```
|
|
2009-11-26 03:13 |
|
|
junyee
中级用户
  
积分 253
发帖 112
注册 2006-5-31
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
Originally posted by lxmxn at 2009-11-26 03:13:
root@~ > grep -xvfb.txt a.txt
2
root@~ > grep -xvfa.txt b.txt
b
root@~ > grep -xfa.txt b.txt
1
3
4
5
6
root@~ >
大哥,这个不是批处理啊???Linux???
Originally posted by lxmxn at 2009-11-26 03:13:
root@~ > grep -xvfb.txt a.txt
2
root@~ > grep -xvfa.txt b.txt
b
root@~ > grep -xfa.txt b.txt
1
3
4
5
6
root@~ >
Dude, this isn't a batch script??? Linux???
|
|
2009-11-27 18:25 |
|
|
ZJHJ
高级用户
   
积分 609
发帖 374
注册 2006-8-2
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
2楼的您不会 用啊
The person on the 2nd floor, you don't know how to use it?
|
|
2009-11-27 21:13 |
|
|
junyee
中级用户
  
积分 253
发帖 112
注册 2006-5-31
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
Originally posted by ZJHJ at 2009-11-27 21:13:
2楼的您不会 用啊 ,
谢谢您的回复,不过,请问,您试过有效了吗>>>???
Originally posted by ZJHJ at 2009-11-27 21:13:
You can't use it on the second floor.
,
Thank you for your reply, but may I ask, have you tried it and it worked?>>>???
|
|
2009-11-27 23:21 |
|
|
HAT
版主
       
积分 9023
发帖 5017
注册 2007-5-31
状态 离线
|
『第 7 楼』:
Re 6楼
使用 LLM 解释/回答一下
测试之前,需要自己去下载一个grep.exe
Before testing, you need to download a grep.exe by yourself.
|

 |
|
2009-11-28 01:19 |
|
|
honcho
初级用户
 
积分 25
发帖 9
注册 2009-10-17
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
@echo off
cd.>a-b.txt
cd.>b-a.txt
cd.>a~b.txt
for /f "delims=" %%i in (a.txt) do (
findstr /i "%%i" b.txt > nul || echo %%i>>a-b.txt
)
for /f "delims=" %%i in (b.txt) do (
findstr /i "%%i" a.txt > nul || echo %%i>>b-a.txt
)
for /f "delims=" %%i in (a.txt) do (
findstr /i "%%i" b.txt > nul && echo %%i>>a~b.txt
)
pause
@echo off
cd.>a-b.txt
cd.>b-a.txt
cd.>a~b.txt
for /f "delims=" %%i in (a.txt) do (
findstr /i "%%i" b.txt > nul || echo %%i>>a-b.txt
)
for /f "delims=" %%i in (b.txt) do (
findstr /i "%%i" a.txt > nul || echo %%i>>b-a.txt
)
for /f "delims=" %%i in (a.txt) do (
findstr /i "%%i" b.txt > nul && echo %%i>>a~b.txt
)
pause
|
|
2009-11-28 12:28 |
|
|
junyee
中级用户
  
积分 253
发帖 112
注册 2006-5-31
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
Originally posted by honcho at 2009-11-28 12:28:
@echo off
cd.>a-b.txt
cd.>b-a.txt
cd.>a~b.txt
for /f "delims=" %%i in (a.txt) do (
findstr /i "%%i" b.txt > nul || echo %%i>>a-b.txt
)
for /f "deli ...
谢谢 .很好用,
另感谢lxmxn版主热心解答,您给的办法也是可行的.
Originally posted by honcho at 2009-11-28 12:28:
@echo off
cd.>a-b.txt
cd.>b-a.txt
cd.>a~b.txt
for /f "delims=" %%i in (a.txt) do (
findstr /i "%%i" b.txt > nul || echo %%i>>a-b.txt
)
for /f "deli ...
Thanks. It works well.
Also, thanks to moderator lxmxn for the enthusiastic answer. The method you provided is also feasible.
|
|
2009-11-28 12:41 |
|
|
ZJHJ
高级用户
   
积分 609
发帖 374
注册 2006-8-2
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
Originally posted by junyee at 2009-11-27 23:21:
,
谢谢您的回复,不过,请问,您试过有效了吗>>>???
是你实在太太.......不会了.....
setlocal EnableDelayedExpansion
cd.>1.txt
for /f "delims=" %%i in (b.txt) do SET %%i=A
for /f "delims=" %%j in (a.txt) do if /I not defined %%j echo %%j>>1.txt
endlocal EnableDelayedExpansion
cd.>2.txt
for /f "delims=" %%i in (a.txt) do SET %%i=A
for /f "delims=" %%j in (b.txt) do if /I not defined %%j echo %%j>>2.txt
setlocal
cd.>3.txt
for /f "delims=" %%i in (a.txt) do SET %%i=A
for /f "delims=" %%j in (b.txt) do if /I defined %%j echo %%j>>3.txt
处理你的文件只要0.07秒
比第 8 楼的代码效率快26.7倍
Last edited by ZJHJ on 2009-11-28 at 22:01 ]
Originally posted by junyee at 2009-11-27 23:21:
,
Thank you for your reply, but, may I ask, have you tried it and it worked?>>>???
You are really too much....... No way.....
setlocal EnableDelayedExpansion
cd.>1.txt
for /f "delims=" %%i in (b.txt) do SET %%i=A
for /f "delims=" %%j in (a.txt) do if /I not defined %%j echo %%j>>1.txt
endlocal EnableDelayedExpansion
cd.>2.txt
for /f "delims=" %%i in (a.txt) do SET %%i=A
for /f "delims=" %%j in (b.txt) do if /I not defined %%j echo %%j>>2.txt
setlocal
cd.>3.txt
for /f "delims=" %%i in (a.txt) do SET %%i=A
for /f "delims=" %%j in (b.txt) do if /I defined %%j echo %%j>>3.txt
Processing your file only takes 0.07 seconds
26.7 times faster than the code in post 8
Last edited by ZJHJ on 2009-11-28 at 22:01 ]
|
|
2009-11-28 21:30 |
|
|
honcho
初级用户
 
积分 25
发帖 9
注册 2009-10-17
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
Originally posted by ZJHJ at 2009-11-28 21:30:
是你实在太太.......不会了.....
setlocal EnableDelayedExpansion
cd.>1.txt
for /f "delims=" %%i in (b.txt) do SET %%i=A
for /f "delims=" %%j in (a.txt) do if ...
很赞同,此法效率极高。
另:本着最简优效的原则,
第三个环境无须改变即可。
setlocal
cd.>1.txt
for /f "delims=" %%i in (b.txt) do SET %%i=A
for /f "delims=" %%j in (a.txt) do if /I not defined %%j echo %%j>>1.txt
endlocal
cd.>2.txt
cd.>3.txt
for /f "delims=" %%i in (a.txt) do SET %%i=A
for /f "delims=" %%j in (b.txt) do if /I not defined %%j (echo %%j>>2.txt) else (echo %%j>>3.txt)
Originally posted by ZJHJ at 2009-11-28 21:30:
You're really too... no more...
setlocal EnableDelayedExpansion
cd.>1.txt
for /f "delims=" %%i in (b.txt) do SET %%i=A
for /f "delims=" %%j in (a.txt) do if ...
I quite agree, this method is extremely efficient.
Also: In line with the principle of simplicity and optimal efficiency,
the third environment does not need to be changed.
setlocal
cd.>1.txt
for /f "delims=" %%i in (b.txt) do SET %%i=A
for /f "delims=" %%j in (a.txt) do if /I not defined %%j echo %%j>>1.txt
endlocal
cd.>2.txt
cd.>3.txt
for /f "delims=" %%i in (a.txt) do SET %%i=A
for /f "delims=" %%j in (b.txt) do if /I not defined %%j (echo %%j>>2.txt) else (echo %%j>>3.txt)
|
|
2009-11-29 01:32 |
|
|
junyee
中级用户
  
积分 253
发帖 112
注册 2006-5-31
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
谢谢楼上诸位。
上述三种方法都是可行的。
findstr 这个我能看懂,可是执行效率似乎低了些,处理10K的文本要近20秒。
grep 这个需要第三方程序,并且,文本不能太大,到几K的时候程序就会报错。
10/11Floor 这个很神奇,可是我看不明白呀,能不能帮忙解释一下这个用法??。
setlocal
...
endlocal
????
Thanks to the诸位 upstairs.
The above three methods are all feasible.
findstr I can understand this, but the execution efficiency seems a bit low. It takes nearly 20 seconds to process a 10K text.
grep This requires a third-party program, and the text cannot be too large. When it reaches a few K, the program will report an error.
10/11Floor This is very magical, but I don't understand it. Can you help explain this usage??.
setlocal
...
endlocal
????
|
|
2010-2-1 22:47 |
|
|
ldr2zjj
初级用户
 
积分 167
发帖 95
注册 2007-5-6
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
怎麼不用FC呢???FC是用來比較不同的啊~~但是我不會寫
Why not use FC? FC is used to compare different ones~~ But I can't write it
|
|
2010-2-3 20:15 |
|
|
lovebaby001
新手上路

积分 12
发帖 12
注册 2010-3-24
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
我在网上找到一个最简单的代码
比较1.txt和2.txt,然后把结果输出到text.txt中去
需对比的文件内容复制到1.txt
把另一个含有不同内容的文件内容复制到2.txt
把以下代码保存成*.bat文件
fc 1.txt 2.txt > text.txt
然后双击批处理文件生成text.txt文件
来源自: www.Pay-4u.Com
完整原文网址: http://www.pay-4u.com/article/18046.html
I found a simplest code online.
Compare 1.txt and 2.txt, then output the result to text.txt.
Copy the content of the file to be compared into 1.txt.
Copy the content of another file with different content into 2.txt.
Save the following code as a *.bat file.
fc 1.txt 2.txt > text.txt
Then double-click the batch file to generate the text.txt file.
Source from: www.Pay-4u.Com
Complete original article URL: http://www.pay-4u.com/article/18046.html
|
|
2010-10-1 16:18 |
|