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-06-22 23:10
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to read a text file in the following format with a script? [Solved, thanks to everyone.] View 4,934 Replies 33
Floor 31 Posted 2007-01-05 09:22 ·  中国 广西 南宁 联通
初级用户
Credits 54
Posts 25
Joined 2006-09-29 02:15
19-year member
UID 63991
Status Offline
How to delete the spaces and dates at the end of each line in the final output list.txt???

----------------------------------------------------------
c:\my\ab.exe 2007.10.26
d:\cde.com 2007.1.1
c:\f.bat 2007.1.3
----------------------------------------------------------

----------------------------------------------------------
c:\my\ab.exe
d:\cde.com
c:\f.bat
----------------------------------------------------------
Floor 32 Posted 2007-01-05 09:43 ·  中国 广西 南宁 联通
初级用户
Credits 54
Posts 25
Joined 2006-09-29 02:15
19-year member
UID 63991
Status Offline
Sorry, I just found out that scoring is possible. Everyone has worked hard. I'll add more after lifting the restriction.
Floor 33 Posted 2007-01-05 09:52 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
If the path does not contain the & symbol, it will be very easy to handle. However, if it contains it, it will be more difficult. The following demonstration code borrows from a section of code I posted the other day (click here to view), which can be compatible with other special symbols in the path except the percent sign:

@echo off
for /f "delims=" %%i in (list.txt) do call :pickup "%%i"
pause
goto :eof

:pickup
set "route=%~1"
call :antitone "%route%"
call :intercept "%str%"
call :antitone "%route%"
echo "%str%"
goto :eof

:antitone
set str=
set "var=%~1"
:loop1
if not "%var:~0,1%"=="" set "str=%str%%var:~-1%"
set "var=%var:~0,-1%"
if not "%var%"=="" goto loop1
goto :eof

:intercept
for /f "tokens=1*" %%i in (%1) do set "route=%%j"
goto :eof
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
gyfhgyfh +2 2007-01-06 22:46
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 34 Posted 2007-01-05 10:32 ·  中国 广东 深圳 润迅通信集团有限公司
初级用户
Credits 118
Posts 7
Joined 2004-03-27 00:00
22-year member
UID 21290
Gender Male
Status Offline
After reading everyone's replies, I'm really impressed. ;)

[ Last edited by zhaoxf on 2007-1-5 at 11:19 AM ]
Forum Jump: