I wrote this script to create and edit a large number of websites based on a template site and a collection of text files which have the relevant strings in them delimited by colons. I run it and the shell doesn't produce any errors, but when it gets to the for loop where it actually has to edit some text, it just stops. The shell just sits there.
#! /bin/sh
echo "Please enter city database location"
read datcity
echo "Please enter prefix database location"
read datprefix
echo "Please enter originals database location"
read datorginal
echo "Please enter corrections database location"
read datcorrect
echo "Please enter substitution database location"
read datsub
echo "Please enter working directory location:"
read work
echo "Please enter location for template websites:"
read start
for city in `awk -F':' '{print $0}' $datcity | sed "s/:/ /"g`
do
for prefix in `awk -F':' '{print $0}' $datprefix | sed "s/:/ /"g`
do
cd $work
cp -r $start $work
projectname=`echo "$prefix$city.com" | sed "s/ //"g`
mv `basename $start` $projectname
echo "Creating $projectname now"
cd $projectname
for site in `ls | grep .html`
do
sed -i "s/`basename $start`/$projectname/"g $site
done
echo "Creating keyword storage"
touch storage
echo "Storage created"
for site in `ls | grep .html`
do
var=1
awk '/Keywords/{print $0}' $site > storage
for edit in `awk -F':' '{print $0}' $datorginal | sed "s/:/ /"g`
do
sed -i "s/$edit/`awk -F':' -v count=$var '{print $count}' $datcorrect`/"g $storage
echo "change made"
let var=var+1
done
sed -i "s/`awk '/Keywords/{print $0}' $site`/`cat storage`/"g $site
done
echo "Removing keyword storage"
sudo rm storage
echo "Storage removed"
echo "Creating description storage"
touch storage
echo "Storage created"
for site in `ls | grep .html`
do
var=1
awk '/Description/{print $0}' $site > storage
for edit in `awk -F':' '{print $0}' $datorginal | sed "s/:/ /"g `
do
sed -i "s/$edit/`awk -F':' -v count=$var '{print $count}' $datcorrect`/"g $storage
echo "change made"
let var=var+1
done
sed -i "s/`awk '/Description/{print $0}' $site`/`cat storage`/"g $site
done
echo "Removing Description storage"
sudo rm storage
echo "Storage removed"
for site in `ls | grep .html`
do
echo "start 1"
var=1
for keys in `awk -F':' '{print $0}' $datorginal | sed "s/:/ /"g`
do
echo "start 2"
sed -i "s/`awk -F':' -v count=$var '{print $count}' $datorginal`/`grep -m 1 $city $datcorrect | awk -F':' -v count=$var '{print $count}'`/"g $site
echo "change $count made to $site"
let var+=1
done
echo "$site changed"
done
for sub in `awk -F':' '{print $0}' $datsub | grep -m 1 $city | sed "s/:/ /"g`
do
if [ "`echo $sub`" == "`echo $city `" ]
then
echo "Substituting files in $projectname now"
elif [ "`echo $sub | grep .jpg`" ]
then
cp -r $sub $projectname/images
elif [ "`echo $sub | grep .gif`" ]
then
cp -r $sub $projectname/images
elif [ "`echo $sub | grep .png`" ]
then
cp -r $sub $projectname/images
else
cp -r $sub $projectname
fi
done
done
done
This is the loop that does where it stops:
for site in `ls | grep .html`
do
echo "start 1"
var=1
for keys in `awk -F':' '{print $0}' $datorginal | sed "s/:/ /"g`
do
echo "start 2"
sed -i "s/`awk -F':' -v count=$var '{print $count}' $datorginal`/`grep -m -1 $city $datcorrect | awk -F':' -v "count=$var" '{print $count}'`/"g $site
echo "change $count made to $site"
let var+=1
done
echo "$site changed"
done