Forcing the order of output fields from cut command

后端 未结 2 776
耶瑟儿~
耶瑟儿~ 2021-02-01 14:40

I want to do something like this:

cat abcd.txt | cut -f 2,1 

and I want the order to be 2 and then 1 in the output. On the machine I am testing

2条回答
  •  既然无缘
    2021-02-01 15:23

    This can't be done using cut. According to the man page:

    Selected input is written in the same order that it is read, and is written exactly once.

    Patching cut has been proposed many times, but even complete patches have been rejected.

    Instead, you can do it using awk, like this:

    awk '{print($2,"\t",$1)}' abcd.txt
    

    Replace the \t with whatever you're using as field separator.

提交回复
热议问题