| Forum List • Thread List • Refresh • New Topic • Search • Previous • Next 1 | 1. BUG: File seek not working #10437 Posted by: chucksim 2007-05-03 21:45:24 Last edited by: Jeff Glatt 2007-06-18 16:01:06 (Total edited 1 time) | I have a very large file (90810 lines of 33 chars). I am trying to find the quickest way to read a certain line in the file so I thought I would seek from the end of the file if the line I wanted was over half way down. So I tried the following and it does not seem to work. It seems that trying to seek from the end of the file using READ LINE just sets the pointer to the number of lines specified from the top of the file. If I use READ CHAR it does. (I have to multiply the line number I want by 33 of course.)
Is <xxx READ LINE not an option?
fn='C:\Net\TABLEDATA.TXT'
start = 66700 /* The line I want */
max = 90817 /* Number of lines in the file */
mid = 90817 / 2 /* The midway point */
if start>mid then do start = max-start offset = STREAM(fn, 'C', 'SEEK <'||start 'READ LINE') end else do offset = STREAM(fn, 'C', 'SEEK '||start 'READ LINE') end
/* Check for an error */ IF DATATYPE(offset) \== "NUM" THEN SAY "There was an error seeking."
say offset
say linein(fn)Chuck Simmons | 2. Example script and file #10447 | In the attached example, the say returns 1 indicating start of file Chuck Simmons | 3. #10453 | Ok, that is a bug. Not sure when exactly I can get to fix it. But I'll mention a couple things:
1) If your lines are always a fixed length, then it is a lot faster to use a CHAR seek (and multiply by the length of the line. Don't forget to add 2 chars to the line length to account for the linefeed and newline chars at the end of each line).
2) Reginald already internally tries to optimizes line seeking, so you may not need to do that yourself. | Forum List • Thread List • Refresh • New Topic • Search • Previous • Next 1 |
|
|