Sort files by number at end in bash/perl -


i'm trying sort huge list of files following format:

file-55_357-0.csv file-55_357-1.csv file-55_357-2.csv  file-55_357-3.csv  ... 

is there simple way in bash or perl? in other words, there way write perl script such goes through of them in numerical order? instance, when create my @files, can make sure script goes through them in sorting -- how create my @sorted array? ask because want append these files vertically, , need in sorted order. much!

you can use sort command, neither part of bash nor part of perl.

with input data in input.txt:

file-55_357-123.csv file-55_357-0.csv file-55_357-21.csv  file-55_357-3.csv  

from shell, (any shell, not bash) can following:

$ sort -t- -nk3 input.txt file-55_357-0.csv file-55_357-3.csv file-55_357-21.csv file-55_357-123.csv 

the -t option specifies delimiter, -n says compare numeric values (so 21 comes after 3 rather before) , -k 3 says sort on third field (per delimiter).


Comments

Popular posts from this blog

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -