我有一个文件列表,其中包含我需要排序的版本号
/this/is/a/file/path/product-2.0/file/name/7 /this/is/a/file/path/product-2.0/file/name/10 /this/is/a/file/path/product-2.0/file/name/12 /this/is/a/file/path/product-2.0/file/name/13 /this/is/a/file/path/product-2.0/file/name/6 /this/is/a/file/path/product-2.0/file/name/8 /this/is/a/file/path/product-2.0/file/name/9
当我通过grep管道时它就像这样:
echo $files | sort -n /this/is/a/file/path/product-2.0/file/name/10 /this/is/a/file/path/product-2.0/file/name/12 /this/is/a/file/path/product-2.0/file/name/13 /this/is/a/file/path/product-2.0/file/name/6 /this/is/a/file/path/product-2.0/file/name/7 /this/is/a/file/path/product-2.0/file/name/8 /this/is/a/file/path/product-2.0/file/name/9
我认为-n被文件名中的第一个数字搞糊涂了.
如何按最后一个数字对数字进行排序
Kaizen ~/so_test $cat ztestfile1 | sort -t'/' -n -k10 /this/is/a/file/path/product-2.0/file/name/6 /this/is/a/file/path/product-2.0/file/name/7 /this/is/a/file/path/product-2.0/file/name/8 /this/is/a/file/path/product-2.0/file/name/9 /this/is/a/file/path/product-2.0/file/name/10 /this/is/a/file/path/product-2.0/file/name/12 /this/is/a/file/path/product-2.0/file/name/13
这有帮助吗?
替代方式即独立于位置…..
Kaizen ~/so_test $cat ztestfile1 | sort -V /this/is/a/file/path/product-2.0/file/name/6 /this/is/a/file/path/product-2.0/file/name/7 /this/is/a/file/path/product-2.0/file/name/8 /this/is/a/file/path/product-2.0/file/name/9 /this/is/a/file/path/product-2.0/file/name/10 /this/is/a/file/path/product-2.0/file/name/12 /this/is/a/file/path/product-2.0/file/name/13
请注意其排序中的-V(大写)选项,该选项查看字符串中的数字差异以进行排序…..如版本号.
手册页文字::
-V,--version-sort natural sort of (version) numbers within text