gpt4 book ai didi

linux - 如何根据字段的数值对文件进行排序?

转载 作者:IT老高 更新时间:2023-10-28 12:23:47 25 4
gpt4 key购买 nike

示例file.txt:

  100 foo
2 bar
300 tuu

当使用 sort -k 1,1 file.txt 时,行的顺序不会改变,尽管我们期待:

  2 bar
100 foo
300 tuu

如何根据绝对数值对由数字组成的字段进行排序?

最佳答案

看看man page for sort ...

   -n, --numeric-sort
compare according to string numerical value

所以这里是一个例子......

sort -n filename

关于linux - 如何根据字段的数值对文件进行排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4856030/

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