re: Command line text substitution
re: Command line text substitution
- Subject: re: Command line text substitution
- From: John W Baxter <email@hidden>
- Date: Thu, 16 Jan 2003 19:19:51 -0800
- Envelope-to: email@hidden
At 23:56 -0500 1/10/2003, brian mather wrote:
>
From Paul Skinner:
>
>
>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?
>
>--
>
>Paul Skinner
>
>
>
How about sed?
>
>
sed 's/string1/string2/' filename
>
In the bash shell, it goes roughly like this:
[john@Zeus john]$a='I want AppleScript.'
[john@Zeus john]$b=${a/Apple/Pear}
[john@Zeus john]$echo $b
I want PearScript.
[john@Zeus john]$
The leftmost $ in those lines is the end of the prompt...start reading
after it.
Does that look something like the sed substitution? Yes
Is that an accident? No
Does it look something like the Perl substitution? Yes
Is *that* an accident? No
And for the determined shorteners in the crowd:
[john@Zeus john]$a='I want AppleScript.' ; echo ${a/Apple/Pear}
I want PearScript.
As for how to do it in tcsh: I don't know and no longer care. But it
should be some small syntactic variation on the above.
You can have file globing wild cards in the pattern above (between the pair
of /s, that is, Apple above). ? is any one character and * is any string of
characters including empty...not the same as * in regular expressions.
--John
--
John Baxter Port Ludlow, WA, USA
I am NOT out of the office. I will respond if and when I get around to it.
_______________________________________________
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.