且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Unix中对字母数字字符串排序?

更新时间:2023-02-19 12:35:52

您需要告诉它排序键的起始位置:

You need to tell it where your sorting key starts:

sort -n -k1.4 list.txt

否则,它会从头开始,无法将字符串转换为数字,而无法进行字母比较.

Otherwise it starts from the beginning, fails to convert a string to a number and falls back to alphabetical comparison.