Here is the trouble maker. Actually two scripts-
replace.sh
code:
#!/bin/bash
# This script is a batch-replace tool for changing the value of all
# occurances of a given string. It is strongly suggested that a back up copy of this directory
# and all subdirectories be made be for the execution of this script, as all changes
#are final and are not ' undo-able '.
#The script 'goReplace.sh' needs to be present
# in the same directory for this to run.
#
echo "This script is a batch-replace tool for changing the value of all occurances of a given string. It is strongly suggested that a back up copy of this directory and all subdirectories be made before the execution of this script, as all changes are final and are not ' undo-able '."
echo " "
echo "enter string to be replaced:"
read oldS
OLDS=$oldS
export OLDS
echo "enter replacement string"
read newS
NEWS=$newS
export NEWS
find ../ -type d -exec ./goReplace.sh {} \;
and then we havegoReplace.sh
code:
#this file is called by 'replace.sh'
cd $1
for file in *.txt;do
sed s/$OLDS/$NEWS/ $file>fout
mv fout $file
done
for file in *.html;do
sed s/$OLDS/$NEWS/ $file>fout
mv fout $file
done
for file in *.htm;do
sed s/$OLDS/$NEWS/ $file>fout
mv fout $file
done
for file in *.shtml;do
sed s/$OLDS/$NEWS/ $file>fout
mv fout $file
done
for file in *.php;do
sed s/$OLDS/$NEWS/ $file>fout
mv fout $file
done
rm \*.php
rm \*.htm
rm \*.html
rm \*.shtml
rm \*.txt
clear
echo "All occurrences of $OLDS have been replaced with $NEWS."
echo " "
echo "That was kinda fun....Can we do it again?"
echo " "
My guess is the for loops were eating up too much memory. It works fine on directories and subdirectories with 20 or 30 files, but maybe a few hundred at at time was biting off more than it could chew. Right about now I feel like that pretty much descibes my style of Systems Administration...
I keep thinking of that line from the old movie Airplane- "Looks like I picked the wrong week to quit shooting heroin".
/* Sure, go ahead and code in your fancy IDE. Just remember: it's all fun and games until someone puts an $i out */
(Edited by norm on 09-25-2004 06:56)