Re: Command line text substitution
Re: Command line text substitution
- Subject: Re: Command line text substitution
- From: Philip Aker <email@hidden>
- Date: Sat, 11 Jan 2003 05:47:24 -0800
On Friday, January 10, 2003, at 08:36 AM, Paul Skinner wrote:
Ok, I'm trying to use the right tools. What's the right CL tool for
replacing a string within a string? perl is an obvious choice. So, how
would I replace a given string in another string using do shell > script?
Create this script file such that it has execute permissions.
#!/usr/bin/tclsh
regsub -all -nocase -- [lindex $argv 0] [lindex $argv 1] [lindex $argv
2] res;
puts $res;
Let's call it say "regsub" and place it in your home directory. Now you
can call it like:
~/regsub xxx "xxx yyy xxxyyy" "dirty harry"
--> dirty harry yyy dirty harryyyy
The call parameters are 'searchString' 'stringToSearch'
'replaceString'. That is: "find param 1 in param 2 and replace with
param 3 then return the result". You'll need to put quotes around
strings with spaces in them. However, if calling from 'do shell
script', any AppleScript string variable will suffice for a parameter.
If you don't need the extra carriage return that the script adds to the
result, change the last line of the script to:
puts -nonewline $res;
HTH,
Philip Aker
http://www.aker.ca
_______________________________________________
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.