![]() |
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 15:09 |
47,811 topics / 349,897 posts / today 0 new / 48,256 members |
| DOS批处理 & 脚本技术(批处理室) » A limitation when using for /f. |
| Printable Version 832 / 4 |
| Floor1 abxialiang | Posted 2010-03-08 12:00 |
| 新手上路 Posts 11 Credits 11 | |
|
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 ] |
|
| Floor2 HAT | Posted 2010-03-08 12:53 |
| 版主 Posts 5,017 Credits 9,023 | |
|
First replace 34 with a character that will not appear in the text, then use that character as the column delimiter.
|
|
| Floor3 jarry0932 | Posted 2010-03-09 01:17 |
| 初级用户 Posts 122 Credits 128 | |
|
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?
|
|
| Floor4 HAT | Posted 2010-03-09 12:06 |
| 版主 Posts 5,017 Credits 9,023 | |
|
Yes, the for command will split the string you set into individual characters.
|
|
| Floor5 abxialiang | Posted 2010-03-09 14:11 |
| 新手上路 Posts 11 Credits 11 | |
|
Got it, thanks, moderator.
|
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |