Re: How to parse CSV
Re: How to parse CSV
- Subject: Re: How to parse CSV
- From: Ed Stockly <email@hidden>
- Date: Tue, 22 Jan 2008 09:01:48 -0800
>>>> think that's a bit harsh and have found CSV to be reliable and
consistent, though I'm willing to accept that I may have led a
sheltered life ;-)
>>>I've always found CSV to use:
>>>"," between items on the same row new line (return or linefeed)
to start a new row quotes (") around items that contain a comma or
new line
>>>"" to escape a quote within quotes
>>>"." in decimals
If you're working with CSV files that contain only numbers (not
counting the first row or first column) then CSV is a fine format
that's easy to work with.
We download CSV files every week that also contain text, but the text
is built without commas, tabs or quotes, so those are easy to parse.
(In fact, I had to dig out this script from my archives, turns out it
was written for Mac OS 8.x, haven't looked at it for years and the
user is still using it in Tiger, the only change was to open it in
Script Editor and save it as a Cocoa applet, to eliminate the need
for classic.)
If your data contains text with new lines, commas and quotes it
becomes a major headache.
But, since you're using AppleScript, you can use other programs to
handle the heavy lifting.
As others have suggested, you can open the CSV file in Excel, and
either save as TSV, XML or simply extract the data from the Excel
document.
Directly parsing CSV in pure AppleScript could be done, but it would
be a major headache.
ES
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden