search and replace
search and replace
- Subject: search and replace
- From: Brian Mather <email@hidden>
- Date: Fri, 22 Mar 2002 10:40:14 -0500
List members:
I started dabbling with a script last night to search for a known string of
characters in a few hundred text files.
Some of the text files will have the string, some others will not. If the
string exists I wanted to replace it with another string. My attempt at the
script went something like:
tell application "Finder"
set the_file to choose file -- for development
set foo to read the_file
set got_it to the offset of "sometext" in foo
if got_it is not 0 then
beep 3 -- development again
set file_mark to got_it
set munger to open for access file (the_file) with write
permission
write "some_other_text" to munger starting at file_mark
close access munger
end if
end tell
problem is that the write command overwrites things instead of inserting
them. I'm sure some reg ex stuff would be more elegant but I don't know the
syntax and hadn't the time to learn it last night.
Any thoughts on how I could isolate the retrieved text and replace it with
the new text correctly?
Please cc to my email as I'm on digest mode.
thanks in advance-
Brian Mather
Digital Photographer
610.491.7091
www.globalsports.com
_______________________________________________
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.