使用剪切和粘贴交换列(using cut and paste to swap column)
我有一个像下面的文件,我想交换第二列和第三列。
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来做到这一点,只能剪切和粘贴。
I got a file like below, I want to swap the second column and the third column.
1425 Juan 14.25 4321 George 21.11 6781 Anna 16.77 1451 Ben 21.77 2277 Tuan 18.77Here's the way I used, it works but it's written in two lines.
cut -f1,3 test1.txt > cat cut -f2 test1.txt | paste cat -> resultIs there any way that I can write it in one line?
Comments: Cannot use AWK to do that, only cut and paste.
最满意答案
你可以连接命令; 或&& :
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)You can just connect the commands with ; or &&:
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 -> resultOr, use a shell that supports process substitution:
paste <(cut -f1 test1.txt) <(cut -f3 test1.txt) <(cut -f2 test1.txt)更多推荐
发布评论