Uniq fields [was: tab delimited data file]
Uniq fields [was: tab delimited data file]
- Subject: Uniq fields [was: tab delimited data file]
- From: "Steven D. Majewski" <email@hidden>
- Date: Wed, 25 Jun 2003 17:37:24 -0400
On Wednesday, June 25, 2003, at 04:36 PM, Rick Norman wrote:
I've been using M$ Excel and was hoping to find a way around it. I
wouldn't
object to using perl but I would not even know where to start. Is this
one
of those task that really isn't appropriate for AS or maybe I should
say is
better suited with some other language? I believe that I could finally
hack
out something, there is just the immediate time constraint
(production, you
understand). It seems that reading in the records and storing the
numeric
value being compared and using that to compare the following records
and
determining whether or not they should be written out to the resulting
file
is more than feasible. Thoughts, concerns?
Thanks,
Rick Norman
I would probably do it in python, but in whatever language you want to:
split fields on delimiter
either sort by the desired unique field, so non-unique values will be
adjacent and
then throw out duplicates on a second pass
or stuff records into a dictionary indexed by the unique id, and catch
duplicates in single pass.
( This is assuming that you don't need to preserve the input order in
the output.
If you do, then you need to save and input record count and sort on
that before output. )
Applescript doesn't natively have dicts/assoc. arrays or do sorts.
If you've got an OSAX handy that does one or the other, then you can do
it in AppleScript.
The other option that comes to mind -- totally untried -- is to use
AppleScript Studio and
script calls to an objective-C NSDictionary object. (obviously, an OSX
only solution)
The usual shell method is to pipe output to sort and then to uniq, but
uniq can skip leading fields or characters,
but not trailing ones, so you would have to reorder your data fields,
which is probably more of a pain than
it's worth.
-- Steve Majewski
_______________________________________________
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.