This is an example for the power of awk. Don't try to understand what the script is doing - it was a one time running script for correcting some failures at an IBM JCL to Unix Script migration and it was build step by step until less than 100 Jobs out of 2000 needed manuel corrections.
My personal status of awk after this job changed from 'Hate-Love' to 'love-it-one-time forget-it but-remember-it'.