awk loop refactor