can you please give me a hand with this code which I'm using to build a log?
##Log construction
printf $timestamp >> $temp"logs.txt"
printf " " >> $temp"logs.txt"
printf $filekey >> $temp"logs.txt"
cat $temp$filekey"_content.txt" >> $temp"logs.txt"
This code is into a bash script that contains a loop which is running N times depending on the quantity of lines of certain text file (in this example that text files has 2 lines only), the thing is that the order of the results printed in logs.txt is OK just the first time that this script runs, like here:
2020_09_04--10:09:41 myhost1.ec2.local records_found 62
2020_09_04--10:09:41 myhost2.ec2.local records_found 62
Next time the script runs it amends the logs.txt file but paste results right after the last text found which is spoiling the log format, like here:
2020_09_04--10:09:41 myhost1.ec2.local records_found 62
2020_09_04--10:09:41 myhost2.ec2.local records_found 622020_09_04--10:10:21 myhost1.ec2.local records_found 64
2020_09_04--10:10:21 myhost2.ec2.local records_found 64
The expected results are:
2020_09_04--10:09:41 myhost1.ec2.local records_found 62
2020_09_04--10:09:41 myhost2.ec2.local records_found 62
2020_09_04--10:10:21 myhost1.ec2.local records_found 64
2020_09_04--10:10:21 myhost2.ec2.local records_found 64
Any help is highly appreciated. Thanks. -Alex.