Re: reading large text file
Re: reading large text file
- Subject: Re: reading large text file
- From: Arthur J Knapp <email@hidden>
- Date: Mon, 20 Aug 2001 19:00:03 -0400
>
From: email@hidden
>
Date: Mon, 20 Aug 2001 12:41:18 EDT
>
Subject: reading large text file
>
I have a text file with over 16,000 lines in it. The format for each line is
>
(### denotes a number):
>
>
### ### ### string
>
>
(i.e. "255 42 48 PANTONE 185 CVC")
>
>
What I need to do is search for the line that contains the string ("PANTONE
>
185 CVC") and extract the three numbers into variables. My problem is mostly
>
that the only way I can seem to do this is to read the whole file into a
>
variable and then search the variable. This creates memory issues and I don't
>
want to have to set the applet to 20 Mb RAM just for this, plus it takes too
>
long when the search string is at the beginning.
This is a line by line search:
set a_file to alias "Commander:TestFile"
set file_ref to open for access a_file
repeat
try -- will error out at eof
set para to read (file_ref) before (return)
if para ends with "PANTONE 185 CVC" then
set {n1, n2, n3} to words 1 thru 3 of para
exit repeat
end if
on error number -39 -- eof
-- didn't find "PANTONE 185 CVC"
set {n1, n2, n3} to {missing value, missing value, missing value}
exit repeat
end try
end repeat
close access file_ref
{n1, n2, n3}
Arthur J. Knapp
http://www.stellarvisions.com
mailto:email@hidden
Hey, check out:
http://www.natural-innovations.com/as/