Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read CSV file as Array with AppleScript

I would like to read in a CSV file in as a 2D array and then return it back to a CSV file. Let's say that this is my CSV file. It is an excel file and the | implies the adjacent cell:

family | type
Doctor | Pediatrics
Engineer | Chemical

From what I understand, there are no arrays on applescript, just lists and records. If it would be better to do this with a XLSX file, please let me know.

like image 820
user1385816 Avatar asked May 12 '12 21:05

user1385816


1 Answers

Nigel's CSV-to-list converter is the best I have seen ...

http://macscripter.net/viewtopic.php?pid=125444#p125444

For your example, use these settings:

set csvText to "family | type
Doctor | Pediatrics
Engineer | Chemical"
csvToList(csvText, {separator:"|"}, {trimming:true})

v2

set csvText to read "/Users/user1385816/Desktop/yourfile.csv"
csvToList(csvText, {}, {trimming:true})
like image 162
adayzdone Avatar answered Oct 07 '22 10:10

adayzdone