Swapping columns in a text file

Posted on 2007-09-22

An awk snippet to swap columns in a text file:

awk -F'[ ]' '{ print $2, ": ", $1 }' original.txt >swapped.txt

The '[ ]' is the separator in the original file (a regular expression). The ": " is the separator that is put in the result file.

You can also be done with cut and paste command line tools.

Tags: awk text processing