'shell scripting nested loops. How to run inner loop along with the parent loop [duplicate]
I have two log files with the application names and the failed reasons ,
first.log
Application 01
Application 02
Application 03
Application 04
Application 05
second.log
failed reason : reason 01
failed reason : reason 02
failed reason : reason 03
failed reason : reason 04
failed reason : reason 05
I want to loop trough this log files and write those information's into a new log file. So the required output is,
Application 01 failed reason : reason 01
Application 02 failed reason : reason 02
Application 03 failed reason : reason 03
Application 04 failed reason : reason 04
Application 05 failed reason : reason 05
The way I tried is as follows ,
while read p; do
projectName="$p"
while read x; do
failedReason="$x"
done < second.log
done < first.log
echo $projectName $failedReason >> full.log
I know this approach is wrong because when the parent loop takes a value then the inner loop runs until the last values and assign the last value to the $failedReason. Then it always prints the last value of the second.log
any suggestion for doing this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|