Re: parsing a large text file
Re: parsing a large text file
- Subject: Re: parsing a large text file
- From: Gnarlodious <email@hidden>
- Date: Thu, 6 Jul 2006 15:47:33 -0600
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:
This email sent to email@hidden