Hi,
I have a script that replaces one string with the other in all files under the specified directory.
!/bin/bash
# **************** Change Variables Here ************
startdirectory="/opt/app/properties/tmp_new"
searchterm="Oracle/Middleware/"
replaceterm=""
# **********************************************************
echo "******************************************"
echo "* Search and Replace in Files Version .1 *"
echo "******************************************"
for file in $(grep -l -R $searchterm $startdirectory)
do
sed -e "s/$searchterm/$replaceterm/ig" $file > /tmp/tempfile.tmp
mv /tmp/tempfile.tmp $file
echo "Modified: " $file
done
echo " *** Yay! All Done! *** "
The problem arises when the
searchterm="Oracle/Middleware/"
&
replaceterm=""
which means i want to replace all "Oracle/Middleware/" with blank "" i.e delete "Oracle/Middleware/" string from each file.
Basically the script errors out becoz it is not able to understand interpret the '/' as part of the string.
What should I do ? Please suggest.