Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop help 2

Status
Not open for further replies.

percent

IS-IT--Management
Apr 27, 2004
176
US
I need help with a loop
(All the functions listed I don't need help with - I just need help with the loop portion)

This is what I'd like to do

Code:
#Begin of script

#My functions are here


#loop to here

myfunctions1 #this gets the variable from a file

myfunctions2 #this does "grep -v $var1" to the file that the variable was received from, then removes the lines from the file that have $var1 in them - then saves the new data to the file.

#go to loop - unless there are no longer any lines in the file to process, if this is the case I would like it to go to the "continue point"

#continue point

myfunction3 #this removes any temporary files

#End of script\

Any help would be greatly appreciated -
This is the last part of my script that I need help with

%, 2004
 
Here's an example of a simple loop...
Code:
loop=Y
while [ $loop = Y ]
do
    # your code goes here
    :
    if true # your exit condition goes here
    then
        loop=N
    fi
done
 
Unfortunately goto isn't allowed in any of the flavours of Unix I have used. But how about something like this to read each line of the input file into a variable called line, one line at a time:
Code:
#Start script
#Functions

   cat <file> | while read line
   do
      <commands>
   done

   myfunction3

#End script

I hope that helps.

Mike
 
So would this work

Code:
loop=Y
while [ $loop = Y ]
do

# code goes here
statexit=`cat data_file |wc -l`
if statexit=0 
then
loop=N
fi


%, 2004
 
Forget the post above / I will just play around with this code in order to get it working.

(Thank you very much for the posts - I am going to order a
unix scripting book online - this way I won't end up here asking simple questions)

%, 2004
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top