中国DOS联盟

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

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

中国DOS联盟论坛
现在时间是 2026-06-16 02:16
中国DOS联盟论坛 » DOS疑难解答 & 问题讨论 (解答室) » Need help! output the text file (urgent!) 查看 649 回复 5
楼 主 Need help! output the text file (urgent!) 发表于 2005-10-27 17:22 ·  马来西亚
新手上路
积分 5
发帖 3
注册 2005-10-27 17:04
UID 44162
来自 Malaysia
状态 离线
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 发表于 2005-10-27 17:57 ·  中国 湖北 武汉 联通
高级用户
★★★
积分 587
发帖 302
注册 2005-07-25 17:31
UID 41046
性别 男
状态 离线
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
3 发表于 2005-10-27 18:58 ·  中国 上海 黄浦区 电信
金牌会员
★★★★
积分 4,639
发帖 2,239
注册 2005-01-30 00:00
UID 35785
性别 男
状态 离线
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

usage:

@INSTR: 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 gets the current time and extracts the
hour; %@INSTR 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==123 echo %f >>Ofile
4 Re: Output a file.Need Help!(urgent!!) 发表于 2005-10-28 09:30 ·  马来西亚
新手上路
积分 5
发帖 3
注册 2005-10-27 17:04
UID 44162
来自 Malaysia
状态 离线
Thanks for you all replies, the information very usefull for me.
Ok, i try to do it.
Thanks a lot.
5 Re: Output a file.Need Help!(urgent!!) 发表于 2005-10-28 11:13 ·  马来西亚
新手上路
积分 5
发帖 3
注册 2005-10-27 17:04
UID 44162
来自 Malaysia
状态 离线
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 发表于 2005-10-28 11:57 ·  中国 上海 黄浦区 电信
金牌会员
★★★★
积分 4,639
发帖 2,239
注册 2005-01-30 00:00
UID 35785
性别 男
状态 离线
"%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:

ABCDFG123RTE
DRSERF234TEF
ADASSD123RTZ

and then I execute the command:

for %f in (@ifile) if %@instr==123 echo %f>>ofile


the result Ofile is:

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 ]
论坛跳转: