![]() |
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-12 11:36 |
47,811 topics / 349,897 posts / today 0 new / 48,256 members |
| DOS批处理 & 脚本技术(批处理室) » New question about deleting the first specified character in each of multiple text lines [Closed] |
| Printable Version 1,796 / 2 |
| Floor1 qianxu | Posted 2011-01-02 12:35 |
| 新手上路 Posts 17 Credits 17 | |
|
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 ] |
|
| Floor2 Hanyeguxing | Posted 2011-01-02 15:27 |
| 银牌会员 Posts 897 Credits 1,039 From 在地狱中仰望天堂 | |
|
```
@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 ] ``` |
|
| Floor3 qianxu | Posted 2011-01-02 15:41 |
| 新手上路 Posts 17 Credits 17 | |
|
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. |
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |