Richard MacLemale wrote:
> I want to read a certain specified range of line numbers from a huge text
> file. What's the best way to do this? What I'd like is something like:
>
> open file thisFile
> read from file thisFile from line 189 to line 300
> put it into myVar
> close file thisFile
You can read the file in bits. Try:
constant buffersize = 10 -- the number of lines to read in one step
function readLines thisFile,startLine,endLine
open file thisFile
-- now read the lines we are not interested in
put zero into i
repeat while i < startLine - buffersize
read from file thisFile for buffersize lines
get the result
if it is not empty then throw it
add buffersize to i
end repeat
-- there may be some lines left
put startLine - i into i
if i > 0 then
read from file thisFile for i lines
end if
-- now read what we want and return it
read from file thisFile for endLine - startLine + 1 lines
close file thisFile
return it
end readLines
Hope this helps. You will have to do some experiments to find an optimal
buffersize constant. Note: I have not tried this script, so it will
propably have some bugs!
Regards
R�diger
--------------------------------------------------------------------
GINIT - Gesellschaft fuer integrierte Informationssysteme mbH
--------------------------------------------------------------------
GINIT GmbH
Ruediger zu Dohna email: [EMAIL PROTECTED]
Technologiepark phone: +49-721-96681-63
Emmy-Noether-Str. 9 fax: +49-721-96681-11
D-76131 Karlsruhe www: http://www.ginit.de
--------------------------------------------------------------------
PGP-Fingerprint: F1 BF 9D 95 57 26 48 42 FE F8 E8 02 41 1A EE 3E
--------------------------------------------------------------------
This is the MetaCard mailing list.
Archives: http://www.mail-archive.com/metacard%40lists.best.com/
Info: http://www.xworlds.com/metacard/mailinglist.htm