使用sort命令对数字进行排序 [英] sorting numbers with the sort command

查看:649
本文介绍了使用sort命令对数字进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对以下文件number.txt中的值进行排序,下面是一个示例

I would like to sort the values in the following file numbers.txt, below is an example

1.1
1.2
10.0
2.2
1000.0

但是当我执行以下cmd

However when I execute the following cmd

sort numbers.txt

我得到以下信息:

1.1
1.2
10.0
1000.0
2.2

我需要哪种cmd对数字值进行适当排序?

What cmd to I need to sort the numeric values appropriately?

推荐答案

使用-n标志对数字进行排序,而不是按字典顺序:

Use the -n flag to sort numerically, instead of lexicographically:

sort -n numbers.txt

这篇关于使用sort命令对数字进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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