The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
edit this text file aneuryzma UNIX for Dummies Questions & Answers 2 09-26-2009 09:22 AM
text file editing injeti Shell Programming and Scripting 26 06-04-2008 12:11 PM
Text editing on iPhone using ed drewcifer UNIX for Dummies Questions & Answers 1 03-05-2008 07:15 PM
SED text edit help needed stevefox Shell Programming and Scripting 3 07-11-2007 06:49 AM
Text Editing ginodii UNIX for Dummies Questions & Answers 7 10-19-2006 10:13 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-29-2009
afroCluster afroCluster is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 5
Text editing script does everything but edit text.

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.

Code:
#! /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:

Code:
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

Last edited by afroCluster; 09-30-2009 at 10:36 AM..
  #2 (permalink)  
Old 09-30-2009
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,430
Just a few mistakes
Quote:
Code:
for city in `awk -F':' '{print $0}' $datcity | sed "s/:/ /"g`
Code:
for city in `echo $datcity | sed "s/:/ /"g`
Quote:
Code:
for site in `ls $location | grep .html`
Code:
for site in *.html
Quote:
Code:
if [ "`echo $sub`" == "`echo $city `" ]
Code:
if [ "$sub" == "$city" ]
  #3 (permalink)  
Old 09-30-2009
varontron varontron is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 110
try echoing all the values in the outer and inner loops. it seems like something you want to change may have been moved or changed already.

for instance, set a var to `ls location` and echo the $var value before the loop.
Reply

Bookmarks

Tags
awk, sed, text editing

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:15 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0