![]() |
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-06 05:25 |
48,039 topics / 350,124 posts / today 2 new / 48,251 members |
| DOS批处理 & 脚本技术(批处理室) » [Help] Compare the contents of two text files and output the differences |
| Printable Version 1,186 / 7 |
| Floor1 greenworld | Posted 2007-10-17 14:09 |
| 初级用户 Posts 45 Credits 86 | |
|
I want to compare the contents of two text files and output the different content from the two files.
First I used findstr /v /g:1.txt 2.txt>3.txt pause and it said findstr: the search string is too long Both files are around 450K or so, and most of the content is the same, hehe Then I used for /f %%a in (1.txt) do ( for /f %%b in (2.txt) do ( findstr /v /c:"%%a" "%%b">>3.txt ) ) pause There was no error message this time, but 3.txt is an empty file. So depressing....... Please give me some guidance, experts |
|
| Floor2 scarscc | Posted 2007-10-17 17:04 |
| 新手上路 Posts 4 Credits 7 | |
|
The fc command is specifically for comparing files
Maybe you can give it a try |
|
| Floor3 greenworld | Posted 2007-10-17 18:22 |
| 初级用户 Posts 45 Credits 86 | |
|
The text output by this command doesn't meet my requirements.... there is a lot of extra information. I only want to output the different content in the two files, and I need to use that content for something else...... still asking the experts for advice........
|
|
| Floor4 ZJHJ | Posted 2007-10-17 21:16 |
| 高级用户 Posts 374 Credits 609 | |
|
Comparing two text files over 450k in size, if you use that method and it actually works, it might still take several hours. The more different lines there are, the longer it will take.
|
|
| Floor5 lxmxn | Posted 2007-10-18 01:54 |
| 版主 Posts 4,938 Credits 11,386 | |
|
A.txt
B.txt
Are the contents of a.txt and b.txt considered different or the same? |
|
| Floor6 greenworld | Posted 2007-10-18 12:45 |
| 初级用户 Posts 45 Credits 86 | |
|
Consider them the same. Moderator, please help, many thanks
|
|
| Floor7 zhclsy | Posted 2007-10-18 16:46 |
| 初级用户 Posts 34 Credits 83 | |
|
I couldn't solve it with DOS,
so later I wrote it in C. Anyone who knows, please leave a message, thanks. |
|
| Floor8 ZJHJ | Posted 2007-10-21 21:48 |
| 高级用户 Posts 374 Credits 609 | |
|
To reduce runtime, my method is: use fc ---- delete duplicate lines ---- more +n, and the result is clean. Processing files around 450k generally takes a few dozen seconds.
|
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |