Advertisement

06.25.2008 at 02:36PM PDT, ID: 23516357
[x]
Attachment Details

Simple loop on file read and exit

Asked by Quetysis in Unix Systems Programming

I have a list of files I saved in a text file.  I want to loop through the list for each file and look in three specific directories for it.  I have that part working, except if the file in my list doesn't exist in any of the three directories, I want to skip that file in the list and move on to the next.  This is the part that I am having trouble getting to work.  If anyone can help, I would appreciate it.  I want to run this script on several unix systems.  Not all systems are the same.  Some have files that others do not which is why I have the complete list in a text file so that I can see what files are missing from that specific system.  Make sense?

Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
for FILE in `cat filelist.txt`
    do
      if test -f /directory1/$FILE
      then
          FILE="/directory1/$FILE"
 
      elif test -f /directory2/$FILE
      then
          FILE="/directory2/$FILE"
 
      elif test -f /directory3/$FILE
      then
          FILE="/diretory3/$FILE"
 
      else next FILE
    fi
 
  done
[+][-]06.25.2008 at 06:33PM PDT, ID: 21871153

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]06.26.2008 at 01:19AM PDT, ID: 21872669

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Unix Systems Programming
Sign Up Now!
Solution Provided By: JustUNIX
Participating Experts: 2
Solution Grade: A
 
 
[+][-]06.26.2008 at 01:21AM PDT, ID: 21872681

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.26.2008 at 09:02AM PDT, ID: 21876115

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628