• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Checking for duplicates in lists
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Checking for duplicates in lists


  • Subject: Re: Checking for duplicates in lists
  • From: Bill <email@hidden>
  • Date: Sat, 3 Jan 2004 15:20:15 +0800

What I [would] do:
1. Make myTracks into lines separated with LF (ascii 10):

----------- tested
set text item delimiters to {ascii character of 10}
set myTracks to myTracks as text
-----------

2. Sort the list: use the shell's "sort" command:

----------- tested
set x to quoted form of myTracks
set x to do shell script "echo " & x & " | sort"
-----------

3. Use the regular expressions to suppress duplicates. I use the Satimage osax [1]:

----------- tested
set x to change "^(.+)(\\r\\1)+" into "\\1" in x with regexp
-----------

Sort & suppress duplicates, I would suggest sort -u

but you should be able to program the same thing with the shell's "grep" command.

4. Finally get it as a list (if that's what you really want! Text lines are finally a cool way of handling a list when you have "sort" and the regular expressions).

Emmanuel, would you try & test this primitive handler, s'il vous plait :)


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"}


merci beaucoup
bill
_______________________________________________
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.

  • Follow-Ups:
    • Re: Checking for duplicates in lists
      • From: Graff <email@hidden>
  • Prev by Date: Re: Automating some preferences
  • Next by Date: Re: Checking for duplicates in lists
  • Previous by thread: Re: Checking for duplicates in lists
  • Next by thread: Re: Checking for duplicates in lists
  • Index(es):
    • Date
    • Thread