Copy and Paste Columns in a Tab-Limited Text file

I have this text file with a very large number of columns (10,000+) and I want to move the first column to the position of the six column so that the text file looks like this:

Before cutting and pasting
ID Family Mother Father Trait Phenotype
aaa bbb ccc ddd eee ddd
fff ggg hhh iii jjj ggg

Family Mother Father Trait ID Phenotype
bbb ccc ddd eee aaa ddd
ggg hhh iii jjj fff ggg

It is a tab-limited text file. How do I achieve this? Thank you!

In your example, ID gets to be the 5th column, in your description you say 6th.
Here is the version for 5th; adjust as needed:

awk '{tmp=$1; for(i=2;i<6;i++)$(i-1)=$i; $5=tmp}1' FS='\t' OFS='\t' data

Disregard -- I misread the OP
This should be more efficient. All you need to do is exchange the two fields rather than looping.

awk ' BEGIN { OFS = "\t"; } {x=$1; $1=$6; $6=x; print; }'  <input-file

I don't think so. OP needs the second column become first, etc. after the operation. OP does not want the sixth field to become first.

1 Like

Oh how embarrassing. I completely misread the OP. You are absolutely correct.

Happened to me before :slight_smile: