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-12 10:40
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » New question about deleting the first specified character in each of multiple text lines [Closed] View 1,795 Replies 2
Original Poster Posted 2011-01-02 12:35 ·  中国 北京 朝阳区 联通
新手上路
Credits 17
Posts 17
Joined 2008-11-23 10:42
17-year member
UID 131820
Gender Male
Status Offline
I searched a lot of posts in the forum about deleting the first character of each line of text, but most of them directly delete the first character of each line without specifying conditions, that is, delete all the first characters regardless of what they are.

Now, I have encountered a tricky problem and specifically ask the experts for help.

That is, first determine whether the first character of each line of text is exactly those specific characters I want to delete. If the first character is those specified characters, delete the character without deleting the line.

I just want to delete the characters themselves whose first character contains the special characters "#" and "?" and "@". Even if there are such characters in other positions in this line, it doesn't matter. Just delete the first character with the specified condition.

For example: In 1.txt

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

Finally, the effect I want to achieve is to be saved in 2.txt

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


Thank you各位teachers here first. And on the occasion of the New Year, I wish all teachers happiness.

[ Last edited by qianxu on 2011-1-2 at 15:43 ]
Floor 2 Posted 2011-01-02 15:27 ·  中国 吉林 延边朝鲜族自治州 延吉市 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
```
@echo off
set ""#"=="
set ""?"=="
set ""@"=="
(for /f "delims=" %%a in (1.txt) do (
set a=%%a
setlocal enabledelayedexpansion
if defined "!a:~0,1!" (echo !a:~1!) else echo !a!
Endlocal
))>2.txt

1. Cannot define = as a variable
2. For more complex operations, it is recommended to use third - party command - line tools such as sed
[ Last edited by Hanyeguxing on 2011 - 1 - 2 at 15:29 ]
```
Floor 3 Posted 2011-01-02 15:41 ·  中国 北京 联通
新手上路
Credits 17
Posts 17
Joined 2008-11-23 10:42
17-year member
UID 131820
Gender Male
Status Offline
Thanks to Teacher Hanyeguxing for great help, thank you again, thanks


On the occasion of the New Year, I wish Teacher Hanyeguxing a happy New Year and smooth sailing in 2011.

Also wish all the teachers and experts in the forum a happy New Year and all the best.
Forum Jump: