为了Bash和排序文件 [英] Bash and sort files in order

查看:115
本文介绍了为了Bash和排序文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以previous bash脚本我创建的文件的列表:

  data_1_box
data_2_box
...
data_10_box
...
data_99_box

的事情是,现在我需要将它们连接起来,所以我试图

ls -l命令数据_ *

但我得到

  .....
data_89_box
data_8_box
data_90_box
...
data_99_box
data_9_box

,但我需要在sucession 1,2,3,4来获得,.. 9,...,89,90,91,...,99

它可以在bash做?


解决方案

  LS data_中的数据* |排序-t -n -k _ 2

-n:各种数值结果
-t:域分隔符'_'结果
-k:排序在第二场,你的情况的数字后的第一个_

with a previous bash script I created a list of files:

data_1_box
data_2_box
...
data_10_box
...
data_99_box

the thing is that now I need to concatenate them, so I tried

ls -l data_*

but I get

.....
data_89_box
data_8_box
data_90_box
...
data_99_box
data_9_box

but I need to get in the sucession 1, 2, 3, 4, .. 9, ..., 89, 90, 91, ..., 99

Can it be done in bash?

解决方案

ls data_* | sort -n -t _ -k 2

-n: sorts numerically
-t: field separator '_'
-k: sort on second field, in your case the numbers after the first '_'

这篇关于为了Bash和排序文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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