Hello,
I am re-processing some files when a specific condition is met. The condition is read from the filename. Since files may need to be re-processed a number of times before they no longer meet the condition, I need to know when to stop re-processing. I am having trouble visualizing the proper control structure. What I had in mind was something like,
1: look through the list of files and find those that meet the re-process condition
2: increment a counter to track the number of files that meet the contrition
3: re-process files that meet the condition
4: GOTO 1 unless the counter==0
The above code would nicely keep looping until there were no compliment files found. The somewhat annoying lack of a GOTO statement makes takes this option off of the table, so I need a replacement.
I guess that some kind of a while loop would be the best alternative, but I don't know what bash has to offer for loops other than a do loop.
Can someone make a suggestion for this. I can post more code if that would help.
---------- Post updated at 10:25 PM ---------- Previous update was at 08:44 PM ----------
At the moment, I am trying something like this,
# zero stop condition
STOP=0
# keep looping until stop condition is met
while [ "$STOP" -ne "1" ]
do
###create list of current files
$FILES
### check list for re-process condition and add filename to array
for FILENAME in $FILES
do
if [ "$VALUE1" == "$VALUE2" ]; then
FILENAMES_TO_PROCESS=("${FILENAMES_TO_PROCESS[@]}" "$FILENAME")
fi
done
### check if any files were found to re-process
# if no files are found that meet the re-process condition
if [ "${#FILENAMES_TO_PROCESS[@]}" == "0" ]; then
echo "no files require reprocessing"
# set condition to exit while loop
STOP=1
# if files are found, re-process files on the list
else
# rm file that is being reprocessed
# code to reprocess files that need it
...
if
# do statistics on re-processed files, this will create an updated filename for any re-processed file
# filenames of re-processed files will be re-checked on next loop
done
As far as I can tell, this will re-process all files that need it. Re-processing will create a new set of file names. The code will loop back to check the new set of file names to see if anything still needs to be re-processed. The code will keep looping until no file names are found that need to be re-processed.
I still seem to be incapable of writing code without multiple nested loops.
Is there anything wrong with this that so far?
LMHmedchem