• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: parsing a large text file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: parsing a large text file


  • Subject: Re: parsing a large text file
  • From: Adam Bell <email@hidden>
  • Date: Thu, 06 Jul 2006 20:04:44 -0300
  • Comment:

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:
>esscable.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:

This email sent to email@hidden

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

  • Prev by Date: Re: Jon's CommandsX 3.0d3 - more
  • Next by Date: Re: parsing a large text file
  • Previous by thread: Re: parsing a large text file
  • Next by thread: Re: parsing a large text file
  • Index(es):
    • Date
    • Thread