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-20 16:07
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] How do I process strings within a specific delimiter? View 732 Replies 6
Original Poster Posted 2007-11-05 11:51 ·  中国 台湾 中华电信(HiNet)数据中心
初级用户
Credits 96
Posts 43
Joined 2007-10-31 01:20
18-year member
UID 101245
Gender Male
Status Offline
I have a text whose contents are like this:
∥bc915∥∥∥Ediary 2.53∥59.117.162.144∥2007/08/23/ 01:10:07∥2007/08/23/ 01:10:07∥698∥4∥2007/10/12 13:13∥∥∥∥TATATA∥


The red parts are the parts I want to delete.
And I want to replace the blank parts with "China forever"
And I need to modify only the strings within that delimiter, and not modify anything else

But after writing this much I don't know how to continue

@echo off
for /f "delims=" %%f in ('dir /on/b "1.txt"') do (
for /f "tokens=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 delims=∥" %%i in (%%f) do echo %%i∥∥%%j∥%%k∥%%l∥%%m∥%%n∥%%o∥%%p∥∥∥∥%%q∥>>2.txt
)
pause


Could I trouble the experts to help me write an example
I'll modify it according to my needs
Many thanks ><"

[ Last edited by leo1984 on 2007-11-5 at 11:53 AM
Floor 2 Posted 2007-11-05 12:42 ·  中国 浙江 杭州 电信
高级用户
★★
Credits 537
Posts 219
Joined 2007-08-04 09:43
18-year member
UID 94620
Gender Male
From 杭州--半山
Status Offline
Floor 3 Posted 2007-11-05 12:43 ·  中国 江苏 常州 溧阳市 电信
银牌会员
★★★
Credits 2,404
Posts 946
Joined 2005-09-08 13:44
20-year member
UID 42345
Status Offline
Floor 4 Posted 2007-11-05 18:16 ·  中国 台湾 中华电信(HiNet)数据中心
初级用户
Credits 96
Posts 43
Joined 2007-10-31 01:20
18-year member
UID 101245
Gender Male
Status Offline
Many thanks to the experts for helping
But I want to modify only the string inside %%p, and nothing else should be modified
But I just tried it, and it seems nothing got modified @@?
What is the reason?
Floor 5 Posted 2007-11-05 18:44 ·  中国 香港 腾讯云
银牌会员
★★★
Credits 1,436
Posts 739
Joined 2007-10-11 17:44
18-year member
UID 99469
Gender Male
Status Offline
sed "/∥/ s# #中國萬歲#4;s#/##7;s###7;s#:##5" 1.txt>2.txt

If you can use sed, why not use it??

[ Last edited by abcd on 2007-11-5 at 08:54 PM
Floor 6 Posted 2007-11-05 19:44 ·  中国 江苏 常州 溧阳市 电信
银牌会员
★★★
Credits 2,404
Posts 946
Joined 2005-09-08 13:44
20-year member
UID 42345
Status Offline
Floor 7 Posted 2007-11-05 21:33 ·  中国 台湾 中华电信(HiNet)数据中心
初级用户
Credits 96
Posts 43
Joined 2007-10-31 01:20
18-year member
UID 101245
Gender Male
Status Offline
Many thanks to expert terse for the guidance ^^
One day my teacher, a father for life @@

For expert abcd, it's not that I won't use it @@
It's because I want something I can "understand" and "learn"
Right now I only just know how to read DOS commands and have just started learning to write them
I'm learning bit by bit
Using sed can work successfully, but I haven't learned that part yet ^^
Many thanks for your guidance, and for understanding a beginner
Forum Jump: