![]() |
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-09-26 02:39 |
47,813 topics / 349,918 posts / today 0 new / 48,275 members |
| DOS批处理 & 脚本技术(批处理室) » How to delete all spaces at the beginning of each line in a batch file? |
| Printable Version 2,281 / 7 |
| Floor1 JasonMing | Posted 2007-10-14 18:48 |
| 初级用户 Posts 42 Credits 116 | |
|
I have read this post http://www.cn-dos.net/forum/viewthread.php?tid=25172
The method in it can handle ordinary documents, but there will be problems when used to handle batch files. I want to ask if it can be done through findstr (intercepting from the first non - space character of each line to the last character). |
|
| Floor2 lxmxn | Posted 2007-10-14 19:51 |
| 版主 Posts 4,938 Credits 11,386 | |
|
```@echo off
for /f "tokens=*" %%a in (test.txt) do echo %%a pause ``` |
|
| Floor3 jmz573515 | Posted 2007-10-14 20:09 |
| 银牌会员 Posts 464 Credits 1,212 | |
|
VBS function - LTRIM is easier...
|
|
| Floor4 JasonMing | Posted 2007-10-14 21:36 |
| 初级用户 Posts 42 Credits 116 | |
Originally posted by lxmxn at 2007-10-14 07:51 PM: This is in that post... No... When encountering such a statement, the output changes After output As a result, when running, the vertical bar "|" will be treated as a pipe, and the result will be wrong... |
|
| Floor5 lxmxn | Posted 2007-10-14 21:53 |
| 版主 Posts 4,938 Credits 11,386 | |
|
Please make the problem clearer, I don't quite understand.
I tested and there are no problems. |
|
| Floor6 JasonMing | Posted 2007-10-14 22:17 |
| 初级用户 Posts 42 Credits 116 | |
|
It is the text in the original file:
echo ------------------------------ echo ^| ^| echo ^| 无效程序 ^| echo ------------------------------ After the processing of removing spaces, it becomes like this: echo ------------------------------ echo ^| ^| echo | 无效程序 | echo ------------------------------ Only when there are Chinese characters will this happen. In the second line of echo, it is still output as originally, but in the third line, the original ^| is output as |, and in this way, executing the program after removing spaces will cause errors... |
|
| Floor7 lxmxn | Posted 2007-10-14 23:54 |
| 版主 Posts 4,938 Credits 11,386 | |
|
|
| Floor8 JasonMing | Posted 2007-10-15 22:08 |
| 初级用户 Posts 42 Credits 116 | |
|
Hehe... I tested it and it really works... I used the same command... Why was it like that that day...
Sweat --|| Maybe it's a problem with the machine... By the way, post a small program of the streamlined batch file I made. It has only 3 lines. Don't laugh at me oh... (Function: Delete comments, delete blank lines and spaces at the beginning of each line) |
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |