Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: parsing a large text file



Title: Re: parsing a large text file
At 1:52 PM -0600 7/6/06, email@hidden wrote:
I need help parsing a large text file.
I need to examine the file one line at a time.
I make changes to it and then write it back out as a text file.

In the past I have put it all into one variable with:

set datafileref to (choose file with prompt "Choose the file:")
set file_data to (read datafileref as {text} using delimiter return)

But it doesn't work on a 32MB text file.

I can read the first line with:

set file_data to (read datafileref as {text} until return)

But how do I read the next line? ... and the next, etc., etc.?

The trick with very large files is to take advantage of the parameters
supported by the Scripting Additions' "Read" statement:

function syntax
set theResult to read anything ¬
     from double integer ¬
     for double integer ¬
     to double integer ¬
     before string ¬
     until string ¬
     using delimiter string ¬
     using delimiters {string, ...} ¬
     as type class

Parameter
Required
Type
Description
direct parameter
required
anything
the file reference number, alias, or file reference of the file to read
as
optional
type class
the form in which to read and return data
before
optional
string
Šor read up to but not including this characterŠ
for
optional
double integer
the number of bytes to read from current position; if omitted, read until the end of the fileŠ
from
optional
double integer
starting from this position; if omitted, start at last position read from
to
optional
double integer
Šor stop at this positionŠ
until
optional
string
Šor read up to and including this character

--
DOS

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-users/bellac%40accesscable.net

This email sent to email@hidden

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-users/email@hidden

This email sent to email@hidden

References: 
 >parsing a large text file (From: email@hidden)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.