简体   繁体   English

按包含小数的名称对文件进行排序

[英]Sorting Files by Name Containing Decimals

I have 200 files in my folder that I would like to sort by name.我的文件夹中有 200 个文件,我想按名称排序。 Here is a short list of my files according to the way that my Linux computer sorted them by default.这是我的文件的简短列表,根据我的 Linux 计算机默认对它们进行排序。

Name at 0.2142.png
Name at 0.4284.png
Name at 0.04284.png
Name at 0.6426.png
Name at 0.8568.png
Name at 0.08568.png
...

I would like to resort them by name from lowest to highest, so my list would become我想按名称从低到高使用它们,因此我的列表将变为

Name at 0.04284.png
Name at 0.08568.png
...
Name at 0.2142.png
Name at 0.4284.png
Name at 0.8568.png 
...

(I put elipses in the middle of my list because there are many more files between Name at 0.08568.png and Name at 0.2142.png.) (我将省略号放在我的列表中间,因为在 0.08568.png 的 Name 和 0.2142.png 的 Name 之间有更多的文件。)

I'm still new to writing bash files but I would think I could write one to sort my figures.我对编写 bash 文件还是个新手,但我想我可以写一个来对我的数字进行排序。

Thanks谢谢

Addendum:附录:

Since the file names are so long I abbreviated them as Name at... The real file name is Planetary Vorticity Tilting by Radial Velocity at t = with a number at the end.由于文件名太长,我将它们缩写为 Name at... 真正的文件名是Planetary Vorticity Tilting by Radial Velocity at t = ,末尾有一个数字。 I hope you can understand why I didn't put that in the original question.我希望你能理解为什么我没有把它放在原始问题中。 I'm also pretty sure I said in the comments below that I am new to Linux and Ubuntu, I do not know "how" the file listing is created.我也很确定我在下面的评论中说我是 Linux 和 Ubuntu 的新手,我不知道“如何”创建文件列表。 I have a MatLab code that makes png files based off of my CFD data with the name that I provided above and the appropriate time step.我有一个 MatLab 代码,它根据我在上面提供的名称和适当的时间步长的 CFD 数据制作 png 文件。 When I open the folder on the Linux computer the files are automatically sorted in the way I listed above and I have no idea why.当我在 Linux 计算机上打开文件夹时,文件会按照我上面列出的方式自动排序,我不知道为什么。

If there is any other clarification needed I would be happy to put it here.如果还有其他需要澄清的地方,我很乐意把它放在这里。

Given:鉴于:

$ echo "$files"
Name at 0.2142.png
Name at 0.4284.png
Name at 0.04284.png
Name at 0.6426.png
Name at 0.8568.png
Name at 0.08568.png
Name at 1.11.png

You can do:你可以做:

$ echo "$files" | sort -t.  -k1
Name at 0.04284.png
Name at 0.08568.png
Name at 0.2142.png
Name at 0.4284.png
Name at 0.6426.png
Name at 0.8568.png
Name at 1.11.png

That assumes the prefix Name at is the same in all cases.假设前缀Name at在所有情况下都相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM