![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
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 is unfortunately not so good (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 |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Code:
while read line
do
empl_id=`echo $line | awk ' { print $1; } '`
empl_dir=`echo $line | awk ' { print $2; } '`
done < output_file.txt
The done < output_file.txt thing is another way to read a file. |
|
#3
|
||||
|
||||
|
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
|
|||
|
|||
|
It looks to me like the whole inner loop could be a single awk code block.
|
|
#5
|
||||
|
||||
|
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
|
||||
|
||||
|
Sorry for the short info
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 |
|
#7
|
||||
|
||||
|
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
|
||||
| Google The UNIX and Linux Forums |