I have three bits of awk strung together which seems to do what I need, but could it be done more efficiently? Currently, the three stages are: