Text editing script does everything but edit text.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Text editing script does everything but edit text.
# 1  
Old 09-29-2009
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  
Old 09-30-2009
Just a few mistakes Smilie
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  
Old 09-30-2009
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Text editing/manipulation

Hello all. I need to rearrange a very long text file with the following format. The number of lines in each block is variable, but is between 1 and 10. Any hints what command could I use for this? Thank you. SAMPLE 2600 15 3453 159 3970 486 4327 760 4498 ... (3 Replies)
Discussion started by: yirgacheffe
3 Replies

2. Shell Programming and Scripting

Convert vi editing to text editing

Dear Guru's I'm using Putty and want to edit a file. I know we generally use vi editor to do it. As I'm not good in using vi editor, I want to convert the vi into something like text pad. Is there any option in Putty to do the same ? Thanks for your response. Srini (6 Replies)
Discussion started by: thummi9090
6 Replies

3. Shell Programming and Scripting

Script to edit a text file

hi, could someone share a short script that would process a .txt file and do the following, for example the text file has this form 0:1.0 1:1.0 2:2.0 3:3.0 4:4.0 5:5.0 6:6.0 7:7.0 8:8.0 ... {newline} 9:9.0 10:10.0 11:11.0 12:12.0 13:13.0 14:14.0 15:15.0 16:16.0 17:17.0 ... {newline} and I... (3 Replies)
Discussion started by: c_lady
3 Replies

4. OS X (Apple)

Need Help with GREP REGEX scripts for common BB-EDIT text-editing

Hi Everybody.. I'm a "newbie" to using Command-line... A few half-remembered DOS commands from 30 years ago, and the very handy "Sudo rm -R pathname" REMOVE command... I do a lot of "cleaning" of plain-text OCR text files. with assorted common line-break, punctuation and capitalization... (1 Reply)
Discussion started by: TheMacGuy
1 Replies

5. Shell Programming and Scripting

Edit Text

Hi everyone , i am new in shell scripting and i want to do a simple job. A have in a file a text that looks like : 4770 maniac 20 0 13680 312 240 S 0.0 0.0 0:00.00 pro 4770 maniac 20 0 23448 312 240 S 0.0 0.0 0:00.00 pro 4770 maniac 20 0 33216 312 240 S 0.0 0.0 0:00.00 pro and i want to... (2 Replies)
Discussion started by: pcmaniac
2 Replies

6. Shell Programming and Scripting

Simple script editing text files and running commands

Okay this will probably have multiple parts to it but I don't really want to trouble you guys with more help because I'm a total noob so I can just do the first part by hand (it's just editing a few hundred lines of text in a file; I have to do the same thing on each line and I'm sure there's a... (2 Replies)
Discussion started by: guitarscn
2 Replies

7. Shell Programming and Scripting

Editing text using AWK

France : 40 : John Persia : 50 : John -----Database What i am trying to achieve is to search for a book, and replave the title with the new title echo -n "Title:" read Title echo -n "Author:" read Author echo "new Title" read NewTitle awk 'BEGIN {... (11 Replies)
Discussion started by: gregarion
11 Replies

8. Shell Programming and Scripting

text file editing

Hi, I need some help in text manipulation. I have an input file like this: 7629 "WPCW 19 - CW/AM1, WPCB 40 - FAMN/CORNER, WPCB-DT1 50 - FAMN/CORNER, " W35AW - Various Shopping Pgms W41CF - TBN W47CV - TBN WLLS-LP 49 - AM1 WATCH WPXI 11 N & WPIX 11 CW 1234 "WPCW 19 - CW/AM1,... (26 Replies)
Discussion started by: injeti
26 Replies

9. UNIX for Dummies Questions & Answers

Text editing on iPhone using ed

Hi all, I'm trying to edit a file using ed on an iphone. I am trying to edit a conf file and have managed to get to the directory where the default.conf file is located, however, when I type ed default.conf all i get is a number and then a blank line and a question mark which is why I am... (1 Reply)
Discussion started by: drewcifer
1 Replies

10. UNIX for Dummies Questions & Answers

Text Editing

Hello everybody, I have a sorted text file. some of the lines appear twice or even more. is there an unix utility that removes the extra appearences? Thanks, Ido. (7 Replies)
Discussion started by: ginodii
7 Replies
Login or Register to Ask a Question