modified to use awk in main loop