根据Bash中字段的数值排序 [英] Sorting according to field's numerical value in Bash
本文介绍了根据Bash中字段的数值排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
示例: File.txt的内容:
Example: content of 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 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?
推荐答案
浏览手册页,排序 ...
-n, --numeric-sort
compare according to string numerical value
所以这是一个例子...
So here is an example...
sort -n filename
这篇关于根据Bash中字段的数值排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文