I'm trying to analyze a file that represents a series of data records. Each record has 66 lines in it and I have to pull out certain data from within this 66 line block.
I basically need to say (for example), go to line 8, column 12, and read 17 characters. Assign that string a variable name and print it to another flat file. Then move onto the next field, and the next, etc. Once done with that record, move on to the next record until finished with each 66 line record.
Can anyone give me a hand with this?
Thanks,
Fred
Need help finding strings
I am assuming its not delimited (doesn't have return /LF at the end of each 66 character block). Look up how to use random access files. You will need to write B$ to a file I won't do everything for you!
Code: Select all
OPEN "r", #1, "c:\data3.dat"
i = 7
FIELD #1, 66 AS a$
WHILE EOF(1) = 0
i = i + 1
GET #1, i
b$ = MID$(a$, 12, 17)
PRINT b$
WEND
He said each record had 66 LINES ....
Code: Select all
NRecordLines=66
Linetoread=8
ColToRead=12
Charstoread=17
open "MyData.txt" for input as #1
open "MyOutput.txt" for output as #2
n=0
do
n=n+1
for i=1 to NRecordlines
line input #1,a$
if i=linetoread then print #2; n,mid$(a$,coltoread,charstoread)
next
loop until eof(1)
close
Re: Need help finding strings
I'm having trouble with your specifications.Anonymous wrote:mrfritz44 wrote:I'm trying to analyze a file that represents a series of data records. Each record has 66 lines in it and I have to pull out certain data from within this 66 line block.
I basically need to say (for example), go to line 8, column 12, and read 17 characters. Assign that string a variable name and print it to another flat file. Then move onto the next field, and the next, etc. Once done with that record, move on to the next record until finished with each 66 line record.....
1) Does each record in the file contain 66 lines?
2) Are these lines fixed or variable length?
3) If the lines are fixed length, what is the length?
4) If they are variable in length then they must have some sort of delimiter. If they are variable, then what is the delimeter?
5) As per your example, "go to line 8, column 12, and read 17 characters." Let's call these "extract parameters" consisting of line, column, and number of characters. How many extract parameters apply to each record? What is the complete set of extract parameters?
6) You say "Assign that string a variable name and print it." What kind of "name" did you have in mind. If only for identifying the source of the output field, I suggest assigning a code like record number-line number-column number; i.e. RRRRR-LL-CCC.
7) Approximately how many records are in this file?
You have an interesting problem. Answer my questions and I'd be glad to help you.
*****
I removed the first post for you, to avoid missunderstandings/confusion, I hope that was ok?moneo wrote:Please excuse me. Somehow I didn't get logged in correctly. As a result, I wrote the 2 "guest" posts above, please ignore the first one. The correct one has 7 questions.
*****
I have left this dump.