【问题标题】:using cut and paste to swap column使用剪切和粘贴交换列
【发布时间】:2017-03-21 21:32:31
【问题描述】:

我有一个类似下面的文件,我想交换第二列和第三列。

1425    Juan    14.25
4321    George    21.11
6781    Anna    16.77
1451    Ben    21.77
2277    Tuan    18.77

这是我使用的方式,它可以工作,但它写成两行。

cut -f1,3 test1.txt > cat
cut -f2 test1.txt | paste cat -> result

有什么办法可以写成一行吗?

评论:不能使用 AWK 来做到这一点,只能剪切和粘贴。

【问题讨论】:

    标签: linux cut


    【解决方案1】:

    您可以将命令与;&& 连接:

    cut -f1,3 test1.txt > cat && cut -f2 test1.txt | paste cat -> result
    
    cut -f1,3 test1.txt > cat ; cut -f2 test1.txt | paste cat -> result
    

    或者,使用支持进程替换的 shell:

    paste <(cut -f1 test1.txt) <(cut -f3 test1.txt) <(cut -f2 test1.txt) 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多