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-07-29 07:58
中国DOS联盟论坛 » 论坛回收站 » Another tricky problem encountered, specifically asking experts for advice. View 7,151 Replies 1
Original Poster Posted 2011-01-24 08:25 ·  中国 北京 联通
新手上路
Credits 17
Posts 17
Joined 2008-11-23 10:42
17-year member
UID 131820
Gender Male
Status Offline
Now, I have another tricky problem and specifically ask for help from experts.

That is, first, I need to judge whether the "first n identical and consecutive characters" in each line of text are exactly those specific characters I want to delete. If the "first n identical and consecutive characters" are the specified characters, then delete the "first n identical and consecutive characters", but do not delete the entire line.

I just want to delete the characters themselves whose "first n identical and consecutive characters" contain special characters "#" and "?" and "@". Even if there are such characters in other positions in this line, it doesn't matter. Only the "first n identical and consecutive" specified characters need to be deleted.

For example: In 1.txt

#############abcdefgh#1666666@
#######1234??5##
???????????????????????????6789
????????????????????11111112222?55555?
@@@@@@@@6666#777?88888@9999#


Explanation: I just want to delete the "first n identical and consecutive characters" at the front of the above five lines.
That is, delete the first ############# in the first line, and keep abcdefgh#1666666@
Delete the first ####### in the second line, and keep 1234??5##
Delete the first ??????????????????????????? in the third line, and keep 6789
Delete the first ???????????????????? in the fourth line, and keep 11111112222?55555?
Delete the first @@@@@@@@ in the fifth line, and keep 6666#777?88888@9999#


The final effect I want to achieve is to be saved in 2.txt

abcdefgh#1666666@
1234??5##
6789
11111112222?55555?
6666#777?88888@9999#


Thank you all teachers here first. And on this New Year's Day, I wish all teachers happiness.
Floor 2 Posted 2011-01-24 11:53 ·  中国 江苏 苏州 太仓市 电信
新手上路
Credits 10
Posts 11
Joined 2010-12-24 12:16
15-year member
UID 179776
Gender Male
Status Offline
This is too complicated. I don't remember being able to delete symbols in specified lines with P, but replacing might be possible.
Forum Jump: