2014-10-26 73 views
0

我試圖創建一個將從CSV文件中創建一個字符串的applescript。創建整個文件的字符串非常容易,但我希望能夠掃描特定組織的文件。以下是我的輸入和期望的輸出。使用AppleScript從CSV查找創建字符串

我的CSV:

Org1 Bobby Bob [email protected] 
Org1 Wendy Wen [email protected] 
Org1 Rachel Rach [email protected] 
Org2 Timmy Tim [email protected] 
Org2 Ronny Ron [email protected] 
Org2 Mike Mik [email protected] 

我的AppleScript:

set csv to read csv_input_file as «class utf8» 
set text item delimiters to "," 
set csvParagraphs to paragraphs of csv 

repeat with current_line in paragraphs of csv 
    set organization to text item 1 of current_line 

    --THIS IS WHERE I NEED HELP 
    set others_in_organization to ... 

end repeat 

所需的輸出:

我想創建一個包含逗號分隔的新字符串目前所有其他人的名單租賃組織。例如,第四個條目的組織是「Org2」。所以弦會返回「Timmy Tim,Ronny Ron,Mike Mik」。

任何幫助將是偉大的!謝謝!

回答

2

嘗試......

set myOrg to "Org1" 
set otherPeople to "" 

set csv to "Org1,Bobby Bob,[email protected] 
Org1,Wendy Wen,[email protected] 
Org1,Rachel Rach,[email protected] 
Org2,Timmy Tim,[email protected] 
Org2,Ronny Ron,[email protected] 
Org2,Mike Mik,[email protected]" 

set text item delimiters to "," 
repeat with aLine in paragraphs of csv 
    set textItems to text items of aLine 
    if item 1 of textItems is not myOrg then 
     set otherPeople to otherPeople & item 2 of textItems & ", " 
    end if 
end repeat 
set text item delimiters to "" 

if otherPeople ends with ", " then 
    set otherPeople to text 1 thru -3 of otherPeople 
end if 
return otherPeople