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

标签 linux bash sorting command

示例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/

相关文章:

linux - 基于列连接两个 csv 文件

linux - 使用 Ansible 在 Linux 上安装 Swift 3 + libdispatch

Java 对两个表达式的集合进行排序

c# - DataTable.DefaultView.Sort 不排序

Python3.4 + Django + Ubuntu : unknown encoding: raw-unicode-escape

java - 在 JavaFX 中使用 WebView 会破坏 Linux 上的 UI

linux - cd 命令在 bash 脚本中不起作用

bash - 如何使用 ffmpeg 创建 HLS 主播放列表?

linux - bash 中的简单正则表达式解析

algorithm - timsort与quicksort的比较