linux命令:SORT,根据字段的数值 [英] linux command: SORT, according to field's numerical value

查看:302
本文介绍了linux命令:SORT,根据字段的数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

示例: File.txt的内容:

  100 foo 
2 bar
300 tuu

使用'sort -k 1,1 File.txt ',但是行的顺序不会改变,虽然我们期待:

  2 bar 
100 foo $ b $我们如何根据绝对数字对包含数字的字段进行排序。 strong> value?

解决方案

观看排序的手册页 ...


  -numeric-sort 
根据字符串数值进行比较


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

  sort -n filename 
pre>

Example: content of File.txt:

  100 foo
  2 bar
  300 tuu

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

  2 bar
  100 foo
  300 tuu

How can we sort a field consisting numbers based on the absolute numerical value?

解决方案

Take a peek at the man page for sort...

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

So here is an example...

sort -n filename

这篇关于linux命令:SORT,根据字段的数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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