Swap two columns - awk, sed, python, perl

后端 未结 9 1526
孤独总比滥情好
孤独总比滥情好 2020-12-01 01:03

I\'ve got data in a large file (280 columns wide, 7 million lines long!) and I need to swap the first two columns. I think I could do this with some kind of awk for loop, to

9条回答
  •  余生分开走
    2020-12-01 02:04

    I tried the answer of perreal with cygwin on a windows system with a tab separated file. It didn't work, because the standard separator is space.

    If you encounter the same problem, try this instead:

    awk -F $'\t' ' { t = $1; $1 = $2; $2 = t; print; } ' OFS=$'\t' input_file
    

    Incoming separator is defined by -F $'\t' and the seperator for output by OFS=$'\t'.

    awk -F $'\t' ' { t = $1; $1 = $2; $2 = t; print; } ' OFS=$'\t' input_file > output_file
    

提交回复
热议问题