China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-09 14:35
中国DOS联盟论坛 » 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. View 2,251 Replies 23
Original Poster Posted 2007-04-21 02:26 ·  中国 香港 电讯盈科有限公司
新手上路
Credits 10
Posts 4
Joined 2007-04-21 02:05
19-year member
UID 85905
Gender Male
Status Offline
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!
Floor 2 Posted 2007-04-21 02:32 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
cd.>dst.txt&&for /f "delims=" %i in (src.txt) do findstr /b /e "%i" dst.txt||echo %i>>dst.txt
Floor 3 Posted 2007-04-21 03:55 ·  中国 广东 广州 电信
银牌会员
★★★
Credits 1,206
Posts 517
Joined 2007-03-25 01:18
19-year member
UID 82819
Gender Male
Status Offline
What is the use of this sentence "cd.>dst.txt"?
知,不觉多。不知,乃求知
Floor 4 Posted 2007-04-21 04:09 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
I am worried that the first time during the find process may not execute normally
Floor 5 Posted 2007-04-21 04:20 ·  中国 广东 广州 电信
银牌会员
★★★
Credits 1,206
Posts 517
Joined 2007-03-25 01:18
19-year member
UID 82819
Gender Male
Status Offline
Um, then I understand..
知,不觉多。不知,乃求知
Floor 6 Posted 2007-04-21 04:28 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
Actually, it didn't meet the owner's requirement. I just understand what the owner's requirement is at this moment
Floor 7 Posted 2007-04-21 04:31 ·  中国 广东 广州 电信
银牌会员
★★★
Credits 1,206
Posts 517
Joined 2007-03-25 01:18
19-year member
UID 82819
Gender Male
Status Offline
Hehe, using two for loops is the best way to handle this.
知,不觉多。不知,乃求知
Floor 8 Posted 2007-04-21 04:35 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
The building owner wants to delete all duplicate lines, not keep any.
Floor 9 Posted 2007-04-21 04:38 ·  中国 香港 电讯盈科有限公司
新手上路
Credits 10
Posts 4
Joined 2007-04-21 02:05
19-year member
UID 85905
Gender Male
Status Offline
Excuse me, how to use it? For this problem, my head has been messed up these two days.
Floor 10 Posted 2007-04-21 04:40 ·  中国 香港 电讯盈科有限公司
新手上路
Credits 10
Posts 4
Joined 2007-04-21 02:05
19-year member
UID 85905
Gender Male
Status Offline
『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!
Floor 11 Posted 2007-04-21 04:41 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
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
Floor 12 Posted 2007-04-21 04:42 ·  中国 江苏 苏州 电信
银牌会员
★★★
Credits 1,181
Posts 533
Joined 2006-08-14 12:54
19-year member
UID 60484
Status Offline
版主以前写过一个完全符合楼主要求的代码,搜下吧。
The moderator namejm once wrote a code that completely meets the requirements of the post, just search for it.
Floor 13 Posted 2007-04-21 04:51 ·  中国 香港 电讯盈科有限公司
新手上路
Credits 10
Posts 4
Joined 2007-04-21 02:05
19-year member
UID 85905
Gender Male
Status Offline
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
Floor 14 Posted 2007-04-21 04:59 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
Think carefully, I tried it, it's okay, let's see if there's any mistake.
Floor 15 Posted 2007-04-21 06:28 ·  中国 广东 广州 电信
银牌会员
★★★
Credits 1,206
Posts 517
Joined 2007-03-25 01:18
19-year member
UID 82819
Gender Male
Status Offline
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.
知,不觉多。不知,乃求知
Forum Jump: