Doing multiple tasks in a loop.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Doing multiple tasks in a loop.
# 1  
Old 12-23-2011
Doing multiple tasks in a loop.

I am in the process of updating a folder of hundreds of recipe html files. I've already managed to modify a number of things in each file but I have run into something that's beyond my ability.

I have a text file that I need to insert the contents into the html at a specific point. It creates several link buttons near the top of all the html pages. With the help of several people in this forum, I have a function that does this. I've even modified it for other modifications I have made to the html files and it works well. I've run into a roadblock though. The html recipe files are for a number of food categories and what html I insert for the function I am working on now is dependent upon what category the recipe is in. Unfortunately all these files are in one folder and are not named in a way that they can be sorted into categories. The only way to determine the category is to parse the html of each file.

Here is the function that loops through all the html files and inserts the text file contents in the correct position in each:

Code:
for file in *.htm ; do
while read line
do
grep -q '<div class="recipe"><img' <<<$line && cat cakesandcheesecakes.txt >> "$file".tmp
  echo $line >> "$file".tmp
done < "$file"
done

However, as I have said, the text to insert is dependent on the recipe category. I have text files for each category.

The only way to determine the category of each file is to parse the html. Here are examples from several different categories. The overall format is the same for all 800 files.

Code:
<span class='label'>Category:</span> Cakes and Cheesecakes</p>

<span class='label'>Category:</span> Cookies</p>

<span class='label'>Category:</span> Main Dishes</p>

Once I determine what the category of the current file being processed is I am going to have to call a modified version of the function I have in the first code box that inserts the correct text.

Cakes and Cheesecakes = cakesandcheesecakes.txt
Cookies = cookies.txt
Main Dishes = maindishes.txt
etc., etc.,etc.
(There are 17 categories overall)

I am perplexed regarding how I can loop through each html file, determine the category and insert the appropriate text according to the category.

Any guidance regarding how I need to approach this?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Multiple if within while loop ksh

Hi All, I'm trying to write while loop with multiple if conditions. Each and every if condition with different variables. whenever one if condition fails i have remove the file from filename and have to pick another file and loop should exit until the last file found in filename. Please help... (4 Replies)
Discussion started by: Kayal
4 Replies

2. Shell Programming and Scripting

Reset while loop to loop same file multiple times

Hi, I want to read file multiple times. Right now i am using while loop but that is not working. ex. While read line do while read line2 do echo stmt1 #processing some data based on data., done < file2.txt done < file1.txt # This will have 10... (4 Replies)
Discussion started by: tmalik79
4 Replies

3. Shell Programming and Scripting

Multiple IP Loop

Hey all, I'm trying to do some very basic scripting. I been scouring the board looking at examples but I just can't seem to piece something together. Edit: Now that I look at it, maybe my request is a little more complex and I'm biting off more than I can chew... 1. Take a list of... (3 Replies)
Discussion started by: YouFatPenguine
3 Replies

4. UNIX and Linux Applications

multiple tasks in Linux automatically

How to schedule the multiple tasks in Linux automatically ? (1 Reply)
Discussion started by: saku
1 Replies

5. Shell Programming and Scripting

Background tasks in a loop (bash)

I am trying to use a loop to start tasks 0-3, running 0,1,2 in the background with &. FOLDSET=( 0 1 2 3 ) for FOLDSET in ${FOLDSET} do if ; then BACKGRD="&" else BACKGRD="" fi # start task $FOLDSET task1 -nogui -ni -p $PROJ \ epochs=$EPOS ... (3 Replies)
Discussion started by: LMHmedchem
3 Replies

6. Shell Programming and Scripting

Multiple Threads/Tasks to run parallely using the shell script

Scenario: I have two PCs (named as A & B) which would send some traps to my third PC (named as C). In PC C, I have to write a shell script such that it should accept the datas from both the PC-A & B parallely. So my question is, is it possible to have two different child threads/tasks... (2 Replies)
Discussion started by: nthiruvenkatam
2 Replies

7. Shell Programming and Scripting

please help in multiple for loop

Hi I have these data 0.9>i>0.1 0.45>j>0.01 I want to execute the script file for different number of i and j using the command $ ./scriptfile i j I write this code #bin/bash for ((i>0.1; i<0.9; i++)) for ((j>0.01; j<0.45; j++)) do ./scriptfile $i $j done However, for loop is not... (3 Replies)
Discussion started by: snow
3 Replies

8. Shell Programming and Scripting

Repetitive Tasks: using if..then inside a loop

I thought I was getting pretty good with Bash but this problem is stumping me. Any suggestions would be greatly appreciated. I've written a firewall script that uses a lot of functions. The variables are read into the script from another .conf file earlier on in the code. Most of these... (2 Replies)
Discussion started by: garak
2 Replies

9. Shell Programming and Scripting

for loop with multiple variables ?

I have a script which selects two 'sets' of system LVM device files from a tabular file 'mapfile' using awk : LIVELV=`awk '{print($1)}' mapfile` BCVLV=`awk '{print($3)}' mapfile` I wanted to pass these 'sets' into an LVM command 'loop' along the lines of : lvmerge $BCVLV $LIVELV ie.... (3 Replies)
Discussion started by: fosterian
3 Replies
Login or Register to Ask a Question