Re: tab delimited data file
Re: tab delimited data file
- Subject: Re: tab delimited data file
- From: Rick Norman <email@hidden>
- Date: Fri, 27 Jun 2003 09:55:47 -0500
Joseph,
Perfect, exactly what I was looking for!
Thanks,
Rick Norman
>
From: Joseph Weaks <email@hidden>
>
Date: Wed, 25 Jun 2003 16:51:27 -0500
>
To: Rick Norman <email@hidden>
>
Cc: AppleScript <email@hidden>
>
Subject: Re: tab delimited data file
>
>
On Wednesday, June 25, 2003, at 01:16 PM, Rick Norman wrote:
>
> If you had several tab delimited data files with 1000 records in each and
>
> one of the data fields held a particular number that may repeat several
>
> times and you wanted to reduce the 1000 records down to just one record
>
> each
>
> by that particular number, how would you do it.
>
>
Rick,
>
This should get you started. It does what you asked. Keeps only the first
>
record with the number and then ignores the remaining ones. Of course,
>
change the manner of choosing the files (droplet, default values, ...) to
>
whatever you like.
>
Joe
>
>
-- Begin script
>
set sourcePath to choose file
>
set resultPath to choose file name
>
>
set sourceFile to open for access sourcePath
>
set resultFile to open for access resultPath with write permission
>
>
set numberTracker to {}
>
set tid to text item delimiters
>
set text item delimiters to tab
>
>
try
>
repeat
>
set thisRecord to text items of (read sourceFile before return)
>
if (text item 2 of thisRecord) is not in numberTracker then
>
set originalRecord to (thisRecord as string) & return
>
set numberTracker to numberTracker & (text item 2 of thisRecord)
>
write originalRecord to resultFile starting at eof
>
end if
>
end repeat
>
on error err
>
set text item delimiters to tid
>
close access sourceFile
>
close access resultFile
>
if err is not "End of file error." then
>
display dialog err
>
else
>
display dialog "Thank you sir, may I have another?"
>
end if
>
end try
>
_______________________________________________
>
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.
_______________________________________________
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.