中国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-09 15:40
47,811 topics / 349,896 posts / today 1 new / 48,254 members
DOS批处理 & 脚本技术(批处理室) » Please clarify the specific content or context of "删掉所有重复行" in the batch processing. Because there are different implementation methods for deleting different types of duplicate lines in different scenarios. For example, if it is a text file with lines of text, the general idea is to read line by line, store it in a temporary variable or array, and then judge whether it has been stored before. If not, it is written to a new file. But the specific batch code needs to be further determined according to the actual situation. Please provide more details.
Printable Version  2,258 / 23
Floor1 yohaa Posted 2007-04-21 02:26
新手上路 Posts 4 Credits 10
Is there anyone who knows how to delete all duplicate lines in a text file and leave only non-duplicate lines? For example:
A text file contains the following lines:
a
a
b
c
d
Now I want to delete the duplicate a and leave only the non-duplicate b c d. Can this be done with a batch script?

Thank you everyone!
Floor2 everest79 Posted 2007-04-21 02:32
金牌会员 Posts 1,127 Credits 2,564
cd.>dst.txt&&for /f "delims=" %i in (src.txt) do findstr /b /e "%i" dst.txt||echo %i>>dst.txt
Floor3 flyinspace Posted 2007-04-21 03:55
银牌会员 Posts 517 Credits 1,206
What is the use of this sentence "cd.>dst.txt"?
Floor4 everest79 Posted 2007-04-21 04:09
金牌会员 Posts 1,127 Credits 2,564
I am worried that the first time during the find process may not execute normally
Floor5 flyinspace Posted 2007-04-21 04:20
银牌会员 Posts 517 Credits 1,206
Um, then I understand..
Floor6 everest79 Posted 2007-04-21 04:28
金牌会员 Posts 1,127 Credits 2,564
Actually, it didn't meet the owner's requirement. I just understand what the owner's requirement is at this moment
Floor7 flyinspace Posted 2007-04-21 04:31
银牌会员 Posts 517 Credits 1,206
Hehe, using two for loops is the best way to handle this.
Floor8 everest79 Posted 2007-04-21 04:35
金牌会员 Posts 1,127 Credits 2,564
The building owner wants to delete all duplicate lines, not keep any.
Floor9 yohaa Posted 2007-04-21 04:38
新手上路 Posts 4 Credits 10
Excuse me, how to use it? For this problem, my head has been messed up these two days.
Floor10 yohaa Posted 2007-04-21 04:40
新手上路 Posts 4 Credits 10
『Building 9』:

Excuse me, brother on floor 7, how to use it? For this problem, my head has been messed up these two days, and also thank everest79 for the enthusiastic help!
Floor11 everest79 Posted 2007-04-21 04:41
金牌会员 Posts 1,127 Credits 2,564
My this can only delete the repeated lines

a
a
b
c
d

a
b
c
d
can't
a
a
b
c
d

b
c
d
src.txt is your original text, after execution, dst.txt is the filtered text, switch the cmd to the directory where src.txt is saved, then execute the above line
Floor12 NaturalJ0 Posted 2007-04-21 04:42
银牌会员 Posts 533 Credits 1,181
版主以前写过一个完全符合楼主要求的代码,搜下吧。
The moderator namejm once wrote a code that completely meets the requirements of the post, just search for it.
Floor13 yohaa Posted 2007-04-21 04:51
新手上路 Posts 4 Credits 10
In addition, I ran the command from the brother on the second floor, and it was also a duplicate and couldn't be deleted. After running, it was still
a
a
b
c
d
Floor14 everest79 Posted 2007-04-21 04:59
金牌会员 Posts 1,127 Credits 2,564
Think carefully, I tried it, it's okay, let's see if there's any mistake.
Floor15 flyinspace Posted 2007-04-21 06:28
银牌会员 Posts 517 Credits 1,206
Then defining an .ini file can meet the requirement.

The .ini file contains the things to be deleted.

Then there are still two for loops.
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023