中国DOS联盟论坛

中国DOS联盟

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

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

游客:  注册 | 登录 | 命令行 | 会员 | 搜索 | 上传 | 帮助 »
中国DOS联盟论坛 » DOS疑难解答 & 问题讨论 (解答室) » Need help! output the text file (urgent!)
作者:
标题: Need help! output the text file (urgent!) 上一主题 | 下一主题
libbyooi
新手上路





积分 5
发帖 3
注册 2005-10-27
来自 Malaysia
状态 离线
『楼 主』:  Need help! output the text file (urgent!)

i want to know how to use dos command to output a file (Ofile) from another file (Ifile) by extracting specific records. The records to be extracted are those records where character  position 10 to 12 (in Ifile) has a value of '123'

For example: Ifile have 3 records which are:

ABCDFG123RTE
DRSERF234TEF
ADASSD123RTZ

So now i want to extract the record which from postion 7- 9 hav value 123 into Ofile, so from this case, Ofile will output two records which are:ABCDFG123RTE and ADASSD123RTZ

2005-10-27 17:22
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
fdsiuha
高级用户




积分 587
发帖 302
注册 2005-7-25
状态 离线
『第 2 楼』:  

Maybe C or QBASIC is a better choice to solve the problem...

[ Last edited by fdsiuha on 2005-10-27 at 17:59 ]



欢迎造访DOS的小屋!
http://risky.ik8.com
2005-10-27 17:57
查看资料  访问主页  发短消息 网志   编辑帖子  回复  引用回复
DOSforever
金牌会员





积分 4639
发帖 2239
注册 2005-1-30
状态 离线
『第 3 楼』:  

If the character are not position specific, you can use external command FIND

For example: find "123" Ifile > Ofile

If the character are not case sensitive you can use /i paramater

For example: find/i "abc" Ifile > Ofile
will find the line that contain "abc" "ABC" "Abc" "ABc" ......

If you need the character are position specific, I recommend you use 4DOS as command interpreter (the 4DOS 7.50 is freeware now,you can download it from official website http://www.jpsoft.com or ftp://jpsoft.com. and should be used in DOS and Win9X environment)

you can use its' Variable Function @INSTR

  Quote:
usage:

@INSTR[start,length,string]:  Returns a substring, starting at the position start and continuing for length characters.  If the length is omitted, it will default to the remainder of the string.  If the length is negative, the start is relative to the right side of the string.  The first character in the string is numbered 0; if the length is negative, the last character is numbered 0.

For example, %@INSTR[0,2,%_TIME] gets the current time and extracts the
hour; %@INSTR[1,-2,%_TIME] extracts the seconds.  If the string includes
commas, it must be quoted with double quotes ["] or back-quotes [`].  The
quotes do count in calculating the position of the substring.

If your record of Ifile are left aligned on each line, you try do this

for %f in (@Ifile) do  if %@INSTR[10,3,%%f]==123 echo %f >>Ofile



DOS倒下了,但永远不死
DOS NEVER DIES !

投票调查:
http://www.cn-dos.net/forum/viewthread.php?tid=46187

本人尚未解决的疑难问题:
http://www.cn-dos.net/forum/viewthread.php?tid=15135
http://www.cn-dos.net/forum/viewthread.php?tid=47663
http://www.cn-dos.net/forum/viewthread.php?tid=48747
2005-10-27 18:58
查看资料  发短消息 网志   编辑帖子  回复  引用回复
libbyooi
新手上路





积分 5
发帖 3
注册 2005-10-27
来自 Malaysia
状态 离线
『第 4 楼』:  Re: Output a file.Need Help!(urgent!!)

Thanks for you all replies, the information very usefull for me.
Ok, i try to do it.
Thanks a lot.

2005-10-28 09:30
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
libbyooi
新手上路





积分 5
发帖 3
注册 2005-10-27
来自 Malaysia
状态 离线
『第 5 楼』:  Re: Output a file.Need Help!(urgent!!)

for %f in (@Ifile) do  if %@INSTR[10,3,%%f]==123 echo %f >>Ofile

what is %f stand for, just now i try to do the testing but seem like it not work?

thanks.

Best Regards,
Libbyooi

2005-10-28 11:13
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
DOSforever
金牌会员





积分 4639
发帖 2239
注册 2005-1-30
状态 离线
『第 6 楼』:  

"%f" is the variable to be used in the FOR command. it can be named in any character(s) by you, in other word, it is a variable name only. %a %b %c %abc etc. are valided.

according to your example, I creat a file named "Ifile" that contain the following:

  Quote:
ABCDFG123RTE
DRSERF234TEF
ADASSD123RTZ

and then I execute the command:

  Quote:
for %f in (@ifile) if %@instr[6,3,%f]==123 echo %f>>ofile

the result Ofile is:

  Quote:
ABCDFG123RTE
ADASSD123RTZ

Please note, the paramater of starting at the position is 6. The %f and %%f are equal.

by the way, I am not good at English. If you can understand Chinese, I prefer discuss this question with you in Chinese.

[ Last edited by DOSforever on 2005-10-28 at 12:00 ]



DOS倒下了,但永远不死
DOS NEVER DIES !

投票调查:
http://www.cn-dos.net/forum/viewthread.php?tid=46187

本人尚未解决的疑难问题:
http://www.cn-dos.net/forum/viewthread.php?tid=15135
http://www.cn-dos.net/forum/viewthread.php?tid=47663
http://www.cn-dos.net/forum/viewthread.php?tid=48747
2005-10-28 11:57
查看资料  发短消息 网志   编辑帖子  回复  引用回复

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


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



论坛跳转: