The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Alternative for a while read line loop kabs UNIX for Dummies Questions & Answers 2 04-01-2008 09:25 AM
while read loop w/ a nested if statement - doesn't treat each entry individually littlefrog Shell Programming and Scripting 7 12-11-2007 06:49 PM
Variable in While Loop Nested If geass Shell Programming and Scripting 6 03-26-2007 03:09 PM
nested loop chinog Shell Programming and Scripting 5 04-20-2005 07:45 AM
nested read TioTony Shell Programming and Scripting 2 03-05-2004 12:11 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 06-22-2005
Rakker's Avatar
Registered User
 

Join Date: Jun 2005
Posts: 7
Question 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 . I'm guessing that I'm using read line the totally wrong way, but my knowledge of unix
is unfortunately not so good (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
Reply With Quote
Forum Sponsor
  #2  
Old 06-22-2005
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,298
Code:
       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.
Reply With Quote
  #3  
Old 06-23-2005
Rakker's Avatar
Registered User
 

Join Date: Jun 2005
Posts: 7
Thanx al lot Jim,

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

Greetings
Reply With Quote
  #4  
Old 06-23-2005
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,298
It looks to me like the whole inner loop could be a single awk code block.
Reply With Quote
  #5  
Old 06-23-2005
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,667
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.
Reply With Quote
  #6  
Old 06-24-2005
Rakker's Avatar
Registered User
 

Join Date: Jun 2005
Posts: 7
Sorry for the short info : 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
Reply With Quote
  #7  
Old 06-24-2005
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,667
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.

Code:
while read directoryname ; do
      while read path jpg ; do
             #something goes here I guess
      done < $directoryname/secondfile
done < firstfile
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 05:10 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0