Re: Checking for duplicates in lists
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.