Awk {print} -in the order I determine

For fun, here is the answer provided by ChatGPT:

It looks like you are using awk to parse and process your input file, and you want to store some information in arrays matrix1 and matrix2, then print them out to the output file in a specific order. However, it seems that the order in which the information is printed to the output file is not the same as the order you specified.

To fix this issue, you can try modifying your awk script as follows:

  1. Instead of storing the information you want to print in arrays matrix1 and matrix2, you can store them in separate variables, for example string1, string2, and string3.
/^DATA/ { string1 = $2 }
/^DATA/ { string2 = $2 }
/^DATA/ { string3 = $3 " " $4 }
  1. After you have read and stored all the necessary information from the input file, you can print the variables in the desired order by using a single print statement.
END {
    print string1
    print string2
    print string3
}

This should ensure that the strings are printed in the correct order in the output file.

I hope this helps! Let me know if you have any questions.