Become a MacRumors Supporter for $25/year with no ads, private forums, and more!

SouthernAtHeart

macrumors newbie
Original poster
Nov 6, 2011
28
0
I've spent quite a bit of time reading & searching, and it seems there's lots of talk of this, but I can't put my cursor on it.
I need a script that will ask for a a CSV file and parse it out. The data will have quoted and unquoted values, embedded commas, and newlinefeed in quotes.
The more I search, the more I'm learning that my original plan of writing the script myself is way beyond my scope, so I'm hoping to find someone that has done this already...
 

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
Explain what exactly it is you want to do with your csv file and what the output should be. Ideally post one row from it. awk makes it easy to work with csv files btw.
 
Comment

SouthernAtHeart

macrumors newbie
Original poster
Nov 6, 2011
28
0
Example with 6 fields
One, 2, "three", "4, five", "and a
Carriage return", 123-456-7890
 
Comment

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
Example with 6 fields
One, 2, "three", "4, five", "and a
Carriage return", 123-456-7890

Yes, but what do you want to do with these fields? Are you interested in all rows but only specific columns, which? What output format? CSV?
 
Comment

SouthernAtHeart

macrumors newbie
Original poster
Nov 6, 2011
28
0
Yes, but what do you want to do with these fields? Are you interested in all rows but only specific columns, which? What output format? CSV?

Yes, all the data.
It's for importing contact data. I don't think I'll bother if it can't be done in AppleScript.
 
Comment

Thom_Edwards

macrumors regular
Apr 11, 2003
240
0
A quick Google search of "applescript explode" should do the trick. I took a glance at some of the results and found this one to be pretty good: http://applescript.bratis-lover.net/library/string/#explode

"Explode" or "split" are common text parsing verbs (and functions/methods in programming languages) used for what you are wanting to do. Pick your delimiter (in your case ",") and a line from your file. It will create an array, with each index containing the value from each "column". Do what you will with the array. Then, move on to the next line. Repeat until EOF.

Be careful, though. You say you are using contact information. You might find a comma inside one of your "columns" and I'm not sure how AppleScript will handle it. A lot of times a .csv will wrap text in double-quotes, so that may help.

Good luck!
 
Comment
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.