标题: Need help! output the text file (urgent!)
[打印本页]
作者: libbyooi
时间: 2005-10-27 17:22
标题: 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
作者: fdsiuha
时间: 2005-10-27 17:57
Maybe C or QBASIC is a better choice to solve the problem...
Last edited by fdsiuha on 2005-10-27 at 17:59 ]
作者: DOSforever
时间: 2005-10-27 18:58
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
作者: libbyooi
时间: 2005-10-28 09:30
标题: 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.
作者: libbyooi
时间: 2005-10-28 11:13
标题: 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
作者: DOSforever
时间: 2005-10-28 11:57
"%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 ]