Friday, September 12, 2014

Change order of columns using awk in Unix

If you want to change order of the columns you cannot do this using cut command in Unix.
cut -f 2,4,5,3,1,6 RefSeq_genes.bed
will give you the same order of columns as original file.

Instead using awk command you can easily swap order of columns in your file.

awk '{print($2,"\t",$4,"\t",$5,"\t",$3,"\t",$1,"\t",$6)}' RefSeq_genes.bed > RefSeq_genes_order.bed

No comments:

Post a Comment