Nested while read line loop

Hi,

Can anyone please help me: i'm trying to read a file with directory-names , then go to that directory and read another (output) file to perform some tasks per line (second read line in the part of script below).
The problem is that after the nested while loop has finished, the first while finsihes too. So the first while loop only executes once :confused: . I'm guessing that I'm using read line the totally wrong way, but my knowledge of unix
is unfortunately not so good :frowning: (just started scripting).

(part of script: I left out some irrelevant peaces to make it easier to read)

exec 0< dir_list_file.txt
while read line
do
cat input_file.txt | grep "^>>" | cut -c 4- > output_file.txt
exec 0< output_file.txt
while read line
do
empl_id=`echo $line | awk ' { print $1; } '`
empl_dir=`echo $line | awk ' { print $2; } '`
<... etc..>
done
done

Thanx in advance

       while read line
       do
          empl_id=`echo $line | awk ' { print $1; } '`
          empl_dir=`echo $line | awk ' { print $2; } '`
        
       done  < output_file.txt 

Take this block of code and put it in another separate file. Remove it from the old script and add a lien to the old script to call it from the old script.

The done < output_file.txt thing is another way to read a file.

Thanx al lot Jim,

I will try your sollution, but is there any other way to fix something like this in one script?

Greetings

It looks to me like the whole inner loop could be a single awk code block.

What shell are you using? What does your input data look like? What os? This looks like it should be easy with ksh. But it's hard to tell with so little info.

Sorry for the short info :o : im using the ksh on a sun/solaris and the input data is as following:

To describe the input data is quite complicated, but in a nutshell : I have a a flat-ascii file which contains directory-names. This file I want to read and with every red file, I'm reading the directories on an ftp-site. Then conditionally, after executing an Oracle-database package another text file is written (by this package). This is also a flat file with every line containing a path-name and jpg-filename. In the second read I have to create the path and copy the jpg-file. I hope its a little more clear now. The sollution of Jim is perfect, but I was just curious if I could make a nested while loop reading files...

Thanx for your replies and greetings,
Rakker

I don't have the foggiest idea of what you're trying to do or what your data looks like. But maybe this will help.

while read directoryname ; do
      while read path jpg ; do
             #something goes here I guess
      done < $directoryname/secondfile
done < firstfile
1 Like

Thanx Perderabo!

This was exactly what I was trying to do in the beginning, make a nested loop in which I could read two files. So the sollution was to use the 'done < filename' (which I didnt know) in the while loops.

Many thanx everyone for helping me out with this! You just made a starting programmer unbelievably happy! :smiley: