The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 12:25 PM
while read loop w/ a nested if statement - doesn't treat each entry individually littlefrog Shell Programming and Scripting 7 12-11-2007 09:49 PM
Variable in While Loop Nested If geass Shell Programming and Scripting 6 03-26-2007 06:09 PM
nested loop chinog Shell Programming and Scripting 5 04-20-2005 10:45 AM
nested read TioTony Shell Programming and Scripting 2 03-05-2004 03:11 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-22-2005
Rakker's Avatar
Rakker Rakker is offline
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
  #2 (permalink)  
Old 06-22-2005
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,720
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.
  #3 (permalink)  
Old 06-23-2005
Rakker's Avatar
Rakker Rakker is offline
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
  #4 (permalink)  
Old 06-23-2005
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,720
It looks to me like the whole inner loop could be a single awk code block.
  #5 (permalink)  
Old 06-23-2005
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
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.
  #6 (permalink)  
Old 06-24-2005
Rakker's Avatar
Rakker Rakker is offline
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:26 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0