How to exchange two columns in a table?

Henry Yen blinux-mail at
Mon Jan 8 04:37:49 UTC 2007

On Sat, Jan 06, 2007 at 11:14:40AM +0800, coscell at wrote:
> Thank you! It's just a tab-delimited text file.

Other than the several programming-based approaches suggest so far,
I'll throw in a more simplistic method.  Since the columns are
clearly delineated (and, in this case, by a tab character, which
works perfectly as the default delimiter here), you can just use
"cut" and "paste":

   cut -f1 inputfile > col1
   cut -f2 inputfile > col2
   paste col2 col1 > outputfile

It's easy to generalize this to any number of columns, and any given
column arrangement.

More information about the Blinux-list mailing list