中国DOS联盟论坛

中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net  论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

游客:  注册 | 登录 | 命令行 | 会员 | 搜索 | 上传 | 帮助 »
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [求助]如何对文本进行分段处理?
作者:
标题: [求助]如何对文本进行分段处理? 上一主题 | 下一主题
jmzhwf
新手上路





积分 16
发帖 11
注册 2009-2-4
状态 离线
『楼 主』:  [求助]如何对文本进行分段处理?

如一个文本文件含有大量的:$12,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,(内容不定)

如何指定字符数进行分段,如:
$23,$32,$23,$32,$23,$32,$23,$32,
$23,$32,$23,$32,$23,$32,$23,$32,
$23,$32,$23,$32,$23,$32,$23,$32,
$23,$32,$23,$32,$23,$32,$23,$32,
$23,$32,$23,$32,$23,$32,$23,$32,
$23,$32,$23,$32,$23,$32,$23,$32,
$23,$32,$23,$32,$23,$32,$23,$32,
$23,$32,$23,$32,$23,$32,$23,$32,
$23,$32,$23,$32,$23,$32,$23,$32,

2009-2-19 14:48
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
zhengqian529
初级用户





积分 100
发帖 93
注册 2009-1-14
来自 湖南
状态 离线
『第 2 楼』:  

设置一个计数器N,n从0开始计数,
1. 以“,”为分界符,for /f "delims=," %%i in (a.txt) do (set /a n+=1
2. 如果n<8, 执行set var=%var%,%%i. 如果n=8,执行echo %var%,%%i>>b.txt,然后n重新归0
3.到达文件末尾,跳出循环,再执行一次echo %var%,%%i>>b.txt.
可以了。

2009-2-19 15:38
查看资料  发送邮件  访问主页  发短消息 网志  OICQ (250988158)  编辑帖子  回复  引用回复
moniuming
银牌会员

永远的菜鸟



积分 1335
发帖 574
注册 2007-11-27
来自 广西
状态 离线
『第 3 楼』:  


@echo off
set str=$12,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,$23,$32,
:agn
set/p=%str:~,32%<nul
echo.
if not "%str:~32%"=="" (set str=%str:~32%&goto :agn)
pause


2009-2-19 16:58
查看资料  发短消息 网志   编辑帖子  回复  引用回复

请注意:您目前尚未注册或登录,请您注册登录以使用论坛的各项功能,例如发表和回复帖子等。


可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题



论坛跳转: