|
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
状态 离线
|
|
2005-10-28 11:57 |
|
|