awk '
NR==FNR {
# read the first file, save the desired field order
n = split($0, field_order)
next
}
FNR==1 {
# read the first line of the second file
# store the mapping of field name to existing column number
n = split($0, header)
for (i=1; i<=n; i++)
current_field_order[header[i]] = i
}
{
# output the fields in the desired order
for (i=1; i<=n; i++)
printf "%s%s", $(current_field_order[field_order[i]]), OFS
print ""
}
' file1 file2
Isso destruirá o alinhamento da coluna. Você pode canalizar a saída em | column -t
para torná-lo bonito.