while loop from list


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting while loop from list
# 1  
Old 09-13-2006
while loop from list

is it possible to run a while loop by comparing a variable with a list ?

taglist="<html> </html> <head> </head> <body> </body> <p> </p> <ul> </ul> <li> </li> <em> </em> <title> </title>"

read newtag

while [[ $newtag != $taglist ]]
do
echo "Entry is not in list, please try again'
read newtag

done


thanks
Steffen
# 2  
Old 09-13-2006
Code:
while [ `echo $taglist | grep -c "$newtag"` -ne 1 ]

# 3  
Old 09-13-2006
awesome, thanks.

Since I am new to this, would it be possible to explain what this command does step by step ?

thanks
Steffen
# 4  
Old 09-13-2006
echo $taglist | grep
# display value in a variable taglist and pass that value to grep command
# through pipe

echo $taglist | grep -c "$newtag"
# search for $newtag in $taglist and display its count
# -c option is for count of match of $newtag in $taglist

` ..commands.. `
# execute the commands and gives the return value of the last command
# that is executed. Here in our case we will get the return value of grep

finally we are checking whether count of $newtag in $taglist is not equal to one.
# 5  
Old 09-13-2006
one doubt

What if there are two matching tags? Wont the check fail??
# 6  
Old 09-13-2006
He didn't mention of reading two tags at a time. If that is the case then he has to change code accordingly.
# 7  
Old 09-13-2006
what change would that be ? I have multiple matching tags in another file ?

thanks,
Steffen
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Efficient way to loop through list

i have a variable that contains a list of files: varA="/var/tmp/hello_0_myapp /var/tmp/mello_1_myapp /var/tmp/jello_2_myapp /var/tmp/fello_3_myapp" And i'm calling this variable in several functions: col0 () { FILE=$(echo "${varA}" | egrep "_0_myapp" | sed "s~_0_myapp~~g")... (5 Replies)
Discussion started by: SkySmart
5 Replies

2. Shell Programming and Scripting

While loop a file containing list of file names until the files are found?

Hi, I have a control file which will contain all filenames(300) files. Loop through all the file names in the control files and check the existence of this file in another directory(same server). I need to infinitely(2 hrs) run this while loop until all the files are found. Once a file is found,... (5 Replies)
Discussion started by: laknar
5 Replies

3. Homework & Coursework Questions

Loop to Convert a list from an input file and output it to another file

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: A) Write a script, which will take input from a file and convert the number from Centigrade to Fahrenheit... (5 Replies)
Discussion started by: AliTheSnake
5 Replies

4. Shell Programming and Scripting

scp list of files using FOR LOOP in ksh

hi i want to scp files from remote server B to my local server A... and i have a file containing list of all files to be scped from remote server B there is a passwordless connectivity set between remote server and my local server. need a ksh script.. with a for loop that goes through... (2 Replies)
Discussion started by: billpeter3010
2 Replies

5. UNIX for Dummies Questions & Answers

Iterate/Loop Through XML Node List

I need to load an XML file and loop through a list of nodes in it to execute a shell script for each one using the attributes for each node as parameters for the script. Any ideas? Any help will be much appreciated. (1 Reply)
Discussion started by: bradlecat
1 Replies

6. Shell Programming and Scripting

How to loop(Iterate) through List with foreach(csh)

Hey all,, I know cshell is harmful:) but I am using this just "to know" - for educational purposes!... not for a long-term use. lets say i have a list.. set arr=(x y z e f) I wanna iterate the list with foreach ,, not with while.!! foreach i $arr echo $i end does not work (2 Replies)
Discussion started by: eawedat
2 Replies

7. UNIX for Dummies Questions & Answers

For Loop for a list of tab delimited variables

Hello, I need to run a command for a set of input variables that are present in a tab delimited file, a sample of which is shown below: 1 3749 1 4129 1 5980 2 6201 2 9925 2 6894 3 1338 3 6477 3 6242 3 3632 Every row represents the two input values... (2 Replies)
Discussion started by: Gussifinknottle
2 Replies

8. Shell Programming and Scripting

Displaying list of backup files using for loop

Hi, I want to display list of last 10 backup files (with numbering) from the temporary file c:/tmp/tmp_list_bkp.txt Example : 1) backup_file1 2) backup_file2 3) backup_file3 ........ ........ I tried as below but not working. for file in c:/tmp/tmp_list_bkp.txt do echo... (3 Replies)
Discussion started by: milink
3 Replies

9. UNIX for Dummies Questions & Answers

List & While Loop

I want to store a set of string values in a 1-D array and then iterate the list by using a loop. Please help this dummy:) (1 Reply)
Discussion started by: ngagemaniac
1 Replies

10. Shell Programming and Scripting

Use file as list in for loop...

Can I use a file as the list in a for loop? I tried it like this: workstation=( $(cat /home/me/file) ) for ws in $workstation do command done The contents of file are like: abc def ghi It only read the initial line. Does each item have to be quoted? Do they have to all be... (11 Replies)
Discussion started by: earnstaf
11 Replies
Login or Register to Ask a Question