如何从 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屋!
查看全文