Re: text Files
Re: text Files
- Subject: Re: text Files
- From: "Ruby Madraswala" <email@hidden>
- Date: Mon, 28 Jul 2003 10:41:26 -0400
- Thread-topic: Re: text Files
Thanks, Allen for taking the time. I did fiddle with script and now it works. I have underlined the changes I made. I still have to fine tune it to add some error checking.
Tell application "Finder"
set temps_glos to "ruby-hd:ruby:b4210gs"
---New file file 3
set glos to "ruby-hd:b4012gs1.txt"
---Master List File 2
set glosfile to "ruby-hd:ruby:gloss.txt"
set file1text to read file temps_glos
set wordlist to every paragraph of file1text
createglossary(wordlist, glosfile, glos) of me
end tell
on createglossary(gterm, mainglos, newglos)
set outfile to open for access file newglos with write permission
set od to AppleScript's text item delimiters
repeat with aWord in gterm
set file2Text to read file mainglos -moved within repeat
if file2Text contains aWord then
display dialog aWord
set AppleScript's text item delimiters to ("|" & return & aWord)
set descripionText to text item 2 of file2Text -- THIS HAS TO BE ITEM 2
set AppleScript's text item delimiters to "|" --Next marker
set descriptionText to text item 1 of descripionText
write (aWord & descriptionText & return) to outfile
end if
end repeat
set AppleScript's text item delimiters to od
close access outfile
return
end createglossary
Thanks again
Ruby
> Ruby
> -----Original Message-----
> From: Allen Watson [
mailto:email@hidden]
> Sent: Thursday, July 24, 2003 7:21 PM
> To: Ruby Madraswala
> Subject: Re: Text files
>
> On or near 7/24/2003 1:59 PM, Ruby Madraswala at email@hidden
> observed:
>
>> Thanks Allen for taking the time.
>> Here's the problem I have:
>> File 1 list changes depending from which user it is coming from.
>> File 2 with description is a master file.
>>
>> The script should read one line at a time from file 1, find the matching term
>> in file 2 and extract those paragraphs and write to file 3. I did try what
>> you
>> have suggested, but I get the first paragraph from file 2 for all terms
>> listed
>> in file 1.
>>
> I understand the problem. File 1 can be a different set of terms each time
> while File 2 is unchanging. Right?
>
> I still say you need to read the entire file at once, then process line by
> line; much easier than reading the file one line at a time. Try this,
> putting in the required file paths:
>
> set file1text to read file path-to-file-1
> set wordlist to every paragraph of file1text
> set file2Text to read file path-to-file-2
> set outfile to open for access path-to-file-3 with write permission
> set od to applescript's text item delimiters
> repeat with aWord in wordlist
> -- Find beginning of desired description
> set applescript's text item delimiters to ("|" & return & aWord)
> set descripionText to text item 2 of file2Text
> set applescript's text item delimiters to "|" -- Next marker
> set descriptionText to text item 1 of descriptionText
> write (aWord & descriptionText & return) to outfile
> end repeat
> set applescript's text item delimiters to od
> close access outfile
>
>
>>
>>
>> -----Original Message-----
>> From: Allen Watson [
mailto:email@hidden]
>> Sent: Wednesday, July 23, 2003 8:56 PM
>> To: Ruby Madraswala
>> Subject: Re: Text files
>>
>> On or near 7/22/2003 12:32 PM, Ruby Madraswala at email@hidden
>> observed:
>>
>>> Hi,
>>> I am working on a script having problem with steps 3 & 4. Any help will be
>>> appreciated.
>>>
>>> 1. read File 1- one line at a time, which has a list of terms (number of
>>> lines
>>> in this file may vary from 1 line to 15 lines).
>>> 2. Store each line in a variable (save-word).
>>> 3. Locate save-word in file 2, (file 2 has description for terms in file 1.
>>> description can be of one paragraph or more)
>>> 4. extract paragraph(s) between pipes.
>>> 5. write paragraph(s) to a third file.
>>>
>>> End of script File 3 should have descriptions for all the terms in File 1.
>>>
>>> Example:
>>> File 1
>>> Active Window
>>> Case-sensitive
>>> Clipboard
>>>
>>> File 2 (description)
>>> Bitmap - aaaaaaaaaaaaaaaaaa
>>> Aaaaaaaaaaaaaaaaa.
>>> |
>>> Active Window - the last window you clicked on - the one that's currently
>>> highlighted..............................
>>>
>>> Any keys you press affect this window.
>>>
>
.............................................................................>>
>
> .
>>> ................................................
>>> |
>>> Case sensitive - so on
>>> |
>>>
>>> I have used pipes to separate description, any other suggestion I could
>>> change
>>> that.
>>>
>> Text item delimiters and "lines" should do the trick.
>>
>> --File 1: Read the entire file
>> set wordtext to read file path-to-file
>> set wordlist to every paragraph of wordtext
>>
>> --File 2:
>> set od to applescript's text item delimiters
>> set applescript's text item delimiters to "|"
>> set descripionText to read file path-to-file-2
>> set descriptionList to text items of descriptionText
>> set applescript's text item delimiters to od
>>
>> At this point you have two lists. Apparently the first item of the second
>> list is a bitmap of some kind (you don't explain that). In that case, item 1
>> of wordlist will correspond to item 2 of descriptionList. I think you can
>> figure out the rest, no?
--
Allen <email@hidden>
Scripts for OE and Entourage:
<
http://members.thinkaccess.net/email@hidden/Scripts/>
Entourage questions: <
http://www.entourage.mvps.org/>
_______________________________________________
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.