如何根据文件的字段数值对文件进行排序? [英] How to sort a file, based on its numerical values for a field?

查看:85
本文介绍了如何根据文件的字段数值对文件进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

示例file.txt:

  100 foo
  2 bar
  300 tuu

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

When using sort -k 1,1 file.txt, the order of lines will not change, though we are expecting :

  2 bar
  100 foo
  300 tuu

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

How to sort a field consisting of numbers based on the absolute numerical value?

推荐答案

浏览手册页,排序 ...

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

所以这是一个例子...

So here is an example...

sort -n filename

这篇关于如何根据文件的字段数值对文件进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆