gpt4 book ai didi

linux - 使用剪切和粘贴交换列

转载 作者:太空宇宙 更新时间:2023-11-04 12:32:28 25 4
gpt4 key购买 nike

我有一个如下所示的文件,我想交换第二列和第三列。

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 来做,只能剪切和粘贴。

最佳答案

你可以只用 ;&& 连接命令:

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) 

关于linux - 使用剪切和粘贴交换列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42938487/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com