• 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: Christopher Nebel <email@hidden>
  • Date: Fri, 2 Jan 2004 10:43:47 -0800

On Jan 2, 2004, at 8:04 AM, Emmanuel wrote:

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

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

Nah -- use uniq(1), since that's what it's there for:

set x to do shell script "echo " & x & " | sort | uniq -d"

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).

----------- tested
set text item delimiters to {return} -- by default "sort" inputs LF's and outputs CR's
set myTracks to text items of x -- use "count paragraphs of x" and be more careful if you expect > 4000 items

Or, if you're using Panther, just use "paragraphs of" and don't worry how many there are. Incidentally, "sort" always inputs and outputs LFs. "do shell script", however, mangles line endings in the output to CRs by default. (I never thought it should do this, but it shipped that way, and scripters started relying on it instantly.)


--Chris Nebel
AppleScript Engineering
_______________________________________________
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: Emmanuel <email@hidden>
References: 
 >Re: Checking for duplicates in lists (From: Emmanuel <email@hidden>)

  • Prev by Date: Handling Unicode Text
  • Next by Date: Launch application in the backgroung
  • Previous by thread: Re: Checking for duplicates in lists
  • Next by thread: Re: Checking for duplicates in lists
  • Index(es):
    • Date
    • Thread