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



For such a truly gigantic text file your best bet would be shell. I
normally do something like:

-- copy the file to a temporary location
do shell script "cp -L ~/Music/iTunes/iTunes\\ Music\\ Library.xml
/private/tmp/tmp"
--  truncate playlists
do shell script "sed '/<key>Playlists<\\/key>/,$d'
/private/tmp/tmp>~/Desktop/iTunes.html"
-- remove any Mac returns in the "Comments" field
do shell script "tr -d '" & (ASCII character 13) & "'
<~/Desktop/iTunes.html>/private/tmp/tmp"
-- set up html table columns
do shell script "perl -ne 'print while
s/.*<key>(Name|Artist|Album|Genre|Size|Year|Comments)<\\/key><[^>]*>([^<]*)<\\/[^>]*>/<td
class=\\1>\\2/g' /private/tmp/tmp>~/Desktop/iTunes.html"

As you can see, with each process the file alternates overwriting the
previous completed file. This is an extremely fast and reliable way to
process large files, because each file is read, processed and written
one line at a time. It is also easy to develop since you can examine
each file incrementally. You can see the entire script here:
http://Gnarlodious.com/Apple/AppleScript/Scripts/iTunes-iPage.html

-- Gnarlie
_______________________________________________
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.