On Sat, 2004-07-31 at 19:45, Jerry M. Howell II wrote:
> hello all,
>
> I appreciate everyone that got me going in the right direction with a
> sed alternative. After some searching I even found a way to get it to
> search recursive and add an extension to the end IE .html or .php and it
> is working wonderfully. Now for the part I haven't gotten a grasp on yet
> the handling of special characters. The situation I'm dealing with right
> now is converting a string hostbyk.com//order to hostbyk.com/order in
> like 100+ html files. how would I do that with the following.
>
> #!/bin/sh
>
> # Need some information from you
> echo "what directory do you wish to search in?"
> read dir
> echo""
> echo "what extension?"
> read ext
> echo""
> echo "what word or string are we looking for?"
> read old
> echo ""
> echo "what do you wish to replace it with"
> read new
>
> cd $dir
> perl -p -i -e 's/'$old/$new/g' $(find . -name \*.$ext
>
Finally figured it out. Just in case anyone else needs to work with it
the syntax for this instance was
find . -name *.html -exec perl -pi.bak -e "s|\Q$old|$new|g" {} \;
of course this is a shell script passed through the perl interpreter so
it's not true perl but the concept still holds and when I write a true
perl script this is the way I'll write it. The important part that
allied to perl is the following
s|\Q$old|$new|g instead of s/$old/$new/g
The \Q tells it to "quote the / in hostbyk/services instead of literally
take it as the / that separates $old from $new. Hope I explained that
well enough. If someone else is better at explaining it feel free to
elaborate. Also, if someone has a better way or alternative, feel free
to explain.
--
Jerry M. Howell II
email admin: usalug.org
sys admin: hostbyk
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>