如何从Bash对包含通用前缀和后缀的字符串进行数字排序? [英] How to sort strings that contain a common prefix and suffix numerically from Bash?
本文介绍了如何从Bash对包含通用前缀和后缀的字符串进行数字排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是文件列表:
some.string_100_with_numbers.in-it.txt
some.string_101_with_numbers.in-it.txt
some.string_102_with_numbers.in-it.txt
some.string_23_with_numbers.in-it.txt
some.string_24_with_numbers.in-it.txt
some.string_25_with_numbers.in-it.txt
现在,我想对它进行数字排序.以* 23 *开头,以* 102 *结尾.
Now I would like to sort it numerically. Starting with *23* and ending with *102*.
我尝试了-n
和-g
. -t
在这些混乱的字符串中无济于事.
I have tried -n
and -g
. -t
does not help in these messy strings.
我可以忽略带选项的数字前导字符串吗?还是我必须精明又能脚本化?
Can I ignore leading strings to the number with an option or do I have to be clever and script?
推荐答案
使用ls -lv
在手册页中:
-v natural sort of (version) numbers within text
这篇关于如何从Bash对包含通用前缀和后缀的字符串进行数字排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文