Re: Checking for duplicates in lists
Re: Checking for duplicates in lists
- Subject: Re: Checking for duplicates in lists
- From: Graff <email@hidden>
- Date: Sat, 03 Jan 2004 03:23:55 -0500
On Jan 3, 2004, at 2:20 AM, Bill wrote:
on shellSort from l
-- unix line ending '\n'
set LF to ASCII character 10
set tmpList to {}
repeat with i in l
set end of tmpList to (contents of i) & LF
end repeat
set tmp to quoted form of (tmpList as Unicode text)
-- paragraph 1 is ""
-- sort -u is t sort & suppress duplicates
return paragraphs 2 thru -1 of (do shell script "echo " & tmp & " |
sort -u")
end shellSort
set sList to {"index.html", "TMA02a.doc", "TMA02a.doc", ".DS_Store",
".localized", "ip.txt", "change TextEdit encoding.scpt", "Chapter 11
Aggression.txt", "GettingStarted.pdf", "Human aggression.txt",
"index.html", "ip.txt", "Social_Psychology.pdf", "TMA02a.doc",
"TMA02a.rtf", "Tutorial 04 - Content.doc", "Human aggression.txt"}
shellSort of me from sList
-- {".DS_Store", ".localized", "Chapter 11 Aggression.txt",
"GettingStarted.pdf", "Human aggression.txt", "Social_Psychology.pdf",
"TMA02a.doc", "TMA02a.rtf", "Tutorial 04 - Content.doc", "change
TextEdit encoding.scpt", "index.html", "ip.txt"}
You might want to also use the "-f" switch for the sort tool so that it
sorts upper case and lower case the same. Also it is probably simpler
to just use AppleScript's text item delimiters to convert the
AppleScript list to a line-feed delimited list
--------------
on shellSort(l)
-- set delimiters to line-feed, save old setting
set {oldDelims, text item delimiters} to {text item delimiters, ASCII
character 10}
-- coerce list into line-feed delimited text
set tmp to quoted form of (l as text)
-- reset delimiters to old delimiters
set text item delimiters to oldDelims
-- sort text, remove duplicates
set output to (do shell script "echo " & tmp & " | sort -uf")
-- break up output into a list
return every paragraph of output
end shellSort
set sList to {"index.html", "TMA02a.doc", "TMA02a.doc", ".DS_Store",
".localized", "ip.txt", "change TextEdit encoding.scpt", "Chapter 11
Aggression.txt", "GettingStarted.pdf", "Human aggression.txt",
"index.html", "ip.txt", "Social_Psychology.pdf", "TMA02a.doc",
"TMA02a.rtf", "Tutorial 04 - Content.doc", "Human aggression.txt"}
shellSort(sList)
--------------
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.