NEWBIE - Replace Text String in Text File - Help?

Hi All,
Thank you all, once again, for your assistance with my previous enquiry. The solutions provided were clear, effective and readily offered, which is all a learner like myself can ask for.
Now I have a different query…
I have a text file, containing URL links. There are three links which I want to replace, and I need to replace every instance.
The file name is
020327.htm The location is
Macintosh HD:Server:Website:Archive:020327.htm
The strings are:
Old - “detail.cfm”
New - “http://<>/detail.cfm”
Old - “default.html”
New - “http://<>/default.html”
Old - “mailto:John_Smith@email.com
New - “mailto:Luke_Stevenson@hotmail.com
I have tried to find and use some of the Scripting Additions available on the net, however, due to my inexperience with AppleScripts, these attempts have failed.
Any suggestions, direction, experiences would be appreciated.
Thanks again, Luke

He’s done it again!…Another seriously lovely bit of coding from MM. It’s already in my “Snippets” file.

[color=#CC0000][b]textReplace[/b][/color]("I am Marc.", "am", "wish I was as clever as") 

Andreas

: He’s done it again ! …Another seriously lovely bit of coding from MM
: . It’s already in my “Snippets” file. textReplace
: (“I am Marc.”, “am”, “wish I was as clever
: as”) Andreas

Now if I could only remember who I stole it from I could pass on the praise… It looks like a Nigel Garvey production to me.
Marc K. Myers
Marc@AppleScriptsToGo.com
AppleScriptsToGo
4020 W.220th St.
Fairview Park, OH 44126
(440) 331-1074

[3/27/02 5:47:57 PM]

Use one of any number of the scriptable text editors . I use Tex-Edit & BBEdit. I think Appleworks and even MS Word can handle your task (and you may already own one of them). Tex-Edit should meet your needs. If you’re using OSX, use Perl instead of applescript.

: Hi All,

: Thank you all, once again, for your assistance with my previous enquiry. The
: solutions provided were clear, effective and readily offered, which is all
: a learner like myself can ask for.

: Now I have a different query…

: I have a text file, containing URL links. There are three links which I want
: to replace, and I need to replace every instance.

: The file name is

: 020327.htm The location is

: Macintosh HD:Server:Website:Archive:020327.htm

: The strings are: Old - “detail.cfm”

: New - “http:// >/detail.cfm”

: Old - “default.html”

: New - “http:// >/default.html”

: Old - “mailto:John_Smith@email.com

: New - “mailto:Luke_Stevenson@hotmail.com

: I have tried to find and use some of the Scripting Additions available on the
: net, however, due to my inexperience with AppleScripts, these attempts
: have failed.

: Any suggestions, direction, experiences would be appreciated.

: Thanks again, Luke

Read the text file into a variable and then call this handler with the variable, the search string, and the replace string:

on textReplace(theText, srchStrng, replStrng)
        tell (a reference to AppleScript's text item delimiters)
                set {od, contents} to {contents, {srchStrng}}
                try
                        set {textList, contents} to {(text items of theText), {replStrng}}
                        set {newText, contents} to {(textList as text), od}
                        return item 1 of result
                on error errMsg number errNbr
                        set contents to od
                        error errMsg number errNbr
                end try
        end tell
end textReplace

Marc K. Myers
Marc@AppleScriptsToGo.com
AppleScriptsToGo
4020 W.220th St.
Fairview Park, OH 44126
(440) 331-1074

[3/27/02 1:39:21 AM]