I need to reorder the fields of an input file. I was using the following awk statement but I am stumped on how to get it exactly as I need.
I need the output to be tab delimited except for the CITY, NAME and ID. Those last set of columns should be a single field separated by a space. And they are variable in length, ie, can be 1 or 5+ columns in length.
So basically fields 1-7 and the last 2 fields put in their proper positions tab delimited, then put everything else in the last field space delimited.
awk '{ print $1,$8,$2,$(NF-1),$(NF),$3,$4,$5$6$7,$1="",$2="",$3="",$4="",$5="",$6="",$7="",$8="",$0 }'
Input
500 XYZ3849 2 30 1964 09 17 ST CITY NAME AP ID 37 -84
500 XYZ3850 3 40 1998 10 27 ST CITY NAME AP 37 -84
500 XYZ3851 4 50 2013 05 7 ST CITY NAME 37 -84
Needed Output
500 ST XYZ3849 37 -84 2 30 19640917 CITY NAME AP ID
500 ST XYZ3850 37 -84 3 40 19981027 CITY NAME AP
500 ST XYZ3851 37 -84 4 50 20130507 CITY NAME
Any help is appreciated.
Thanks!