accessing a huge text file to gather data for addressbook

Hi… Two things:

#1. I am experiencing odd things— I have a text file with over 13,000 lines of contact information (addressbook data in a particular format), and I am running a script to sort through it and plug the values into address book…

The script works perfectly-- ive tested it numerous times in various ways… but on occasion, I get this weird NSCONTAINER error-- but it’s intermittent… Usually running the script on the exact same file a 2nd time will not produce the same error.

So I am wondering if I need to put a delay in the portion of the script that is adding to addressbook?

#2. The script reads the text file and sorts it by paragraph into a list… This takes a very very long time to do before the script actually begins doing things in addressbook… So I am wondering, is there a way to tell applescript to read a portion of the file, process it, and then read more? Or is it only possible to do it the way im doing it (read the entire file into a list) ?

thank you in advance.

I’ve tested over this file:

And this code is very fast:

set inputFile to alias "path:to:file.txt"
do shell script "sort -f " & quoted form of POSIX path of inputFile & " > /tmp/sorted.txt"

set x to paragraphs of (read ("/tmp/sorted.txt" as POSIX file))

According to Smile’s “chrono”, this code runs in 0.46 seconds.

Are you sure you need read the file in chunks? Perhaps you are sorting by a different field than the first one? If you read the file in chunks of x bytes, how can you sort the “records” if you don’t have all the records to compare?

Perhaps we could help better if you post your code and the file format you’re parsing…

Sorry, I have been tied up with other things…

Well I think I figured out that my NSContainer error was coming from trying to add a card to a group in addressbook… When I removed the line

add myCard to group “addresses” it stopped happening…

so then I tried putting that line back and then adding a delay of .5 seconds in the script and it seems to work fine now… I put the add mycard line in a try block as well just to be safe…