• 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: Peter Waibel <email@hidden>
  • Date: Fri, 7 Jul 2006 10:56:41 +0200


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 read command makes use of the file mark.
When you open a file, the file mark of this file is 0.
The read command reads an amount of bytes and sets the file mark to after the amount of bytes.
The next read command will start at the new file mark.



Try something like this:

set fileRef to open for access (choose file)
repeat
	try
		read fileRef until return
	on error
		close access fileRef
		exit repeat
	end try
end repeat
try
	close access fileRef
end try

Peter
_______________________________________________
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: Folder actions
  • Next by Date: Re: parsing a large text file
  • Previous by thread: parsing a large text file
  • Next by thread: Re: parsing a large text file
  • Index(es):
    • Date
    • Thread