gpt4 book ai didi

linux - 如何排序和忽略空格?

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

我正在尝试对文件进行排序,但无法获得想要的结果。我有这个文件:

742550111       aaa aaa aaa aaa aaa     2008    3       1       1
5816470687 aa a dissertation for the 933 2 2 2

每个字段由一个表格分隔,我想在第二列上排序。

当我尝试 sort test.txt -t\t -k 2 时,输出与文件中的相同。但我想要的输出是:

5816470687      aa a dissertation for the       933     2       2       2
742550111 aaa aaa aaa aaa aaa 2008 3 1 1

我认为这是因为排序忽略了单词之间的空格。

所以我尝试了这个命令:LC_ALL=C sort test.txt -t\t -k 2,但它仍然不起作用。

你有什么想法吗?

最佳答案

Bash 将 $'\t' 替换为真正的制表符:

LC_ALL=C sort file -t $'\t' -k 2 

输出:

5816470687      aa a dissertation for the       933     2       2       2742550111       aaa aaa aaa aaa aaa     2008    3       1       1

关于linux - 如何排序和忽略空格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56098395/

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