awk Useful one-liners - calculating average from a CSV etc Exchanging two columns in tabular data


Example

Given a file using ; as a column delimiter. Permuting the first and the second column is accomplished by

awk -F';' -v 'OFS=;' '{ swap = $2; $2 = $1; $1 = swap; print }'