Rearrange columns using cut

后端 未结 8 1483
难免孤独
难免孤独 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:17

    For the cut(1) man page:

    Use one, and only one of -b, -c or -f. Each LIST is made up of one range, or many ranges separated by commas. Selected input is written in the same order that it is read, and is written exactly once.

    It reaches field 1 first, so that is printed, followed by field 2.

    Use awk instead:

    awk '{ print $2 " " $1}' file.txt
    

提交回复
热议问题