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 14:24
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » A limitation when using for /f. View 830 Replies 4
Original Poster Posted 2010-03-08 12:00 ·  中国 湖南 株洲 电信
新手上路
Credits 11
Posts 11
Joined 2009-12-29 17:21
16-year member
UID 157557
Gender Male
Status Offline
There is a file b.txt whose contents are: aa3vv4bb34cc4dd34ff

I want to use “34” as the delimiter string and extract the strings:

-----------------------------------------
@echo off
for /f "delims=34 tokens=1,2,3*" %%i in (b.txt) do (
echo %%i---%%j---%%k
)
pause
-----------------------------------------
Originally I wanted to use “34” as a delimiter string, so that after processing it would output “aa3vv4bb--cc4dd--ff”, but when the batch file runs it does not treat “34” as a whole, so I did not get the result I wanted (it outputs “aa---vv---bb”). Is there any simple way to do this?

[ Last edited by abxialiang on 2010-3-8 at 12:10 ]
Floor 2 Posted 2010-03-08 12:53 ·  新加坡
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
First replace 34 with a character that will not appear in the text, then use that character as the column delimiter.
Floor 3 Posted 2010-03-09 01:17 ·  中国 天津 电信
初级用户
★★
Credits 128
Posts 122
Joined 2009-09-21 06:24
16-year member
UID 152378
Gender Male
Status Offline
So that means you can't directly use 34 itself as the delimiter? In other words, you can't use a string of length 2 or more as the delimiter?
Floor 4 Posted 2010-03-09 12:06 ·  中国 上海 联通
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
Yes, the for command will split the string you set into individual characters.
Floor 5 Posted 2010-03-09 14:11 ·  中国 湖南 株洲 电信
新手上路
Credits 11
Posts 11
Joined 2009-12-29 17:21
16-year member
UID 157557
Gender Male
Status Offline
Got it, thanks, moderator.
Forum Jump: