How to reverse column order of a file in Linux from the command line

后端 未结 4 496
长发绾君心
长发绾君心 2021-01-04 03:59

I have a file named ip-list with two columns:

IP1    Server1
IP2    Server2

And I want to produce:

4条回答
  •  心在旅途
    2021-01-04 04:52

    More than two columns

    printf "\
    1 2 3 4
    5 6 7 8
    " | awk '{for(i=NF;i>0;i--)printf "%s ",$i;print ""}'
    

    Output:

    4 3 2 1
    8 7 6 5
    

    See also: https://unix.stackexchange.com/questions/46275/swapping-an-unlimited-number-of-columns

    Tested in GNU Awk 4.0.1.

提交回复
热议问题