find files that have number in file name greater than

brucezepplin picture brucezepplin · Mar 26, 2015 · Viewed 9.7k times · Source

If I have 10 files called 01-a.txt, 02-a.txt,...10-a.txt - how can I find the files where the number is greater than 5? I would like a general solution, and I would be putting the contents of all files into one file using something like

cat *.txt > bigfile.txt

I can get files with numbers using

ls *[0-9]*

but can't seem go beyond that.

thanks.

Answer

myaut picture myaut · Mar 26, 2015

You may use seq for that, but it works only if all files have same naming convention:

seq -f "%02g-a.txt" 6 10
06-a.txt
07-a.txt
08-a.txt
09-a.txt
10-a.txt

I.e.:

cat `seq -f "%02g-a.txt" 6 10` > bigfile.txt