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
Post a Comment