1

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?

  • Why not simply `paste -d ' ' first.log second.log >> full.log` ? – M. Nejat Aydin May 13 '22 at 07:29
  • I'd recommend [chepner's answer to "Read from two files line by line and process them simultaneously"](https://stackoverflow.com/questions/42694461/read-from-two-files-line-by-line-and-process-them-simultaneously/42696047#42696047). – Gordon Davisson May 13 '22 at 07:48

0 Answers0