Bash按照Windows的“自然排序顺序” [英] Bash Sort like Windows 'natural sort order'

查看:204
本文介绍了Bash按照Windows的“自然排序顺序”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆PDF,我试图附加在一起,我有一个程序,给定一个文件列表,将它们附加到一个PDF。

I've got a bunch of PDFs that I'm trying to append together, and I've got a program that, given a list of files, will append them to one PDF.

我遇到的问题是,将文件名分配到 sort 不会产生所需的顺序。没有排序的标志给我我想要的。我有以下几个例子:

The issue I'm having is that piping the file names to sort does not produce the desired order. None of the flags of sort give me what I want either. I've got some examples below:

所需的排序顺序:

test1.pdf
test2.pdf
test10.pdf

使用排序::

Achieved sort order using sort:

test1.pdf
test10.pdf
test2.pdf

有关我希望的排序顺序的详细信息,请参阅:

For more info on exactly what constitutes the sort order I desire, see:

http://msdn.microsoft.com /en-us/library/bb759947.aspx

推荐答案

假设您使用GNU排序, code> -V 选项:

Assuming you're using GNU sort, use the-V option:

   -V, --version-sort
          natural sort of (version) numbers within text

对于您的输入,它会产生: / p>

For your input, it'd produce:

test1.pdf
test2.pdf
test10.pdf

这篇关于Bash按照Windows的“自然排序顺序”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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