![]() |
中国DOS联盟-- 联合DOS 推动DOS 发展DOS --联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum |
| 游客 | 登录 | 注册 | 会员 | 搜索 | 中国DOS联盟 |
|
中国DOS联盟论坛 现在时间是 2026-08-17 14:03 |
共 47,814 主题排行 / 349,905 发帖 / 今日 2 篇 / 48,259 会员排行 |
| DOS疑难解答 & 问题讨论 (解答室) » Need help! output the text file (urgent!) |
| 可打印版本 700 / 5 |
| 第1楼 libbyooi | 发表于 2005-10-27 17:22 |
| 新手上路 发帖 3 积分 5 来自 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 |
|
| 第2楼 fdsiuha | 发表于 2005-10-27 17:57 |
| 高级用户 发帖 302 积分 587 | |
|
Maybe C or QBASIC is a better choice to solve the problem...
[ Last edited by fdsiuha on 2005-10-27 at 17:59 ] |
|
| 第3楼 DOSforever | 发表于 2005-10-27 18:58 |
| 金牌会员 发帖 2,239 积分 4,639 | |
|
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
If your record of Ifile are left aligned on each line, you try do this for %f in (@Ifile) do if %@INSTR==123 echo %f >>Ofile |
|
| 第4楼 libbyooi | 发表于 2005-10-28 09:30 |
| 新手上路 发帖 3 积分 5 来自 Malaysia | |
|
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. |
|
| 第5楼 libbyooi | 发表于 2005-10-28 11:13 |
| 新手上路 发帖 3 积分 5 来自 Malaysia | |
|
Re: Output a file.Need Help!(urgent!!) for %f in (@Ifile) do if %@INSTR==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 |
|
| 第6楼 DOSforever | 发表于 2005-10-28 11:57 |
| 金牌会员 发帖 2,239 积分 4,639 | |
|
"%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:
and then I execute the command:
the result Ofile is:
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联盟 -
标准版 ] Sponsored by ifanr Inc | © 2001–2023 |