Sponsored Content
Top Forums Shell Programming and Scripting Doing multiple tasks in a loop. Post 302584563 by Trapper on Friday 23rd of December 2011 04:32:51 PM
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?
 

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

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. 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

7. 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

8. 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

9. 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
rmf(1)							      General Commands Manual							    rmf(1)

NAME
rmf - remove folder (only available within the message handling system, mh) SYNOPSIS
rmf [+folder] [-help] [-[no]interactive] OPTIONS
Prints a list of the valid options to this command. Asks for confirmation before deleting a folder. By default, rmf deletes a folder and its messages without asking for confirmation. If you specify the -interactive option, rmf asks if you are sure before deleting the folder. You are advised to use this option, since when rmf deletes a folder its contents are lost irretrievably. DESCRIPTION
The rmf command removes all of the messages within the current folder, and then removes the folder itself. If there are any files within the folder which are not part of MH, they are not removed, and an error message is displayed. You can specify a folder other than the current folder by using the +folder argument. If you do not specify a folder, and rmf cannot find the current folder,rmf asks you whether you want to delete +inbox instead. If the current folder is removed, it makes +inbox current. Note that the rmf command irreversibly deletes messages that do not have other links, so use it with caution. If the folder being removed is a sub-folder, the parent folder becomes the new current folder, and rmf tells you that this has happened. This provides an easy mechanism for selecting a set of messages, operating on the list, then removing the list and returning to the current folder from which the list was extracted. Using rmf to delete a read-only folder deletes the private sequence and current message information from the file, without affecting the folder itself. If you have sub-folders within a folder, you must delete all the sub-folders before you can delete the folder itself. PROFILE COMPONENTS
Path: To determine the user's Mail directory EXAMPLES
This example shows how rmf asks for confirmation when the -interactive option is used: % rmf -interactive +test Remove folder "test"? y FILES
The user profile. SEE ALSO
rmm(1) rmf(1)
All times are GMT -4. The time now is 10:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy