Rearrange columns using cut

后端 未结 8 1492
难免孤独
难免孤独 2020-11-28 03:53

I am having a file in the following format

Column1    Column2
str1       1
str2       2
str3       3

I want the columns to be rearranged. I tried below

8条回答
  •  难免孤独
    2020-11-28 04:32

    You may also combine cut and paste:

    paste <(cut -f2 file.txt) <(cut -f1 file.txt)
    

    via comments: It's possible to avoid bashisms and remove one instance of cut by doing:

    paste file.txt file.txt | cut -f2,3
    

提交回复
热议问题