Bash and sort files in order

Viewed 59193

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?

8 Answers

I have files in a folder and need to sort them based on the number. E.g. -

abc_dr-1.txt
hg_io-5.txt
kls_er_we-3.txt
sd-4.txt
sl_rt_we_yh-2.txt

I need to sort them based on number. So I used this to sort.

ls -1 | sort -t '-' -nk2
Related