如何根据字段的数值对文件进行排序? [英] How to sort a file, based on its numerical values for a field?
本文介绍了如何根据字段的数值对文件进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
示例file.txt
:
100 foo2 酒吧300图
当使用 sort -k 1,1 file.txt
时,行的顺序不会改变,尽管我们期待:
2 小节100 英尺300图
如何根据绝对数值对由数字组成的字段进行排序?
解决方案
看看 man page for排序...
<块引用> -n, --numeric-sort根据字符串数值比较
所以这里是一个例子......
sort -n 文件名
Example file.txt
:
100 foo
2 bar
300 tuu
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?
解决方案
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
这篇关于如何根据字段的数值对文件进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文