Find files with a number in the file name greater than

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

cat *.txt > bigfile.txt

I can get files with numbers using

ls *[0-9]*

but cannot seem above it.

thank.

+6
source share
4 answers

You can use this seq, but it only works if all files have the 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

Ie:

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

"< _ > - <rest> " < numeric_value > $LIM.

(, 5), (, 05) ...

<rest> .

LIM=5
for file in $(ls);
do
   number=$(echo $file | cut -f1 -d'-');
   [ $number -gt $LIM ] && cat $file >> bigfile.txt;
done
+2

Assuming the folder contains only these files.

This will be a list of all files where number> 5

ls [0-9] * | awk -F '-' '{if ($ 1> 5) print $ 0}'

+1
source
ls *.txt | perl -n -e '$f = $_; $f =~ s/\D//g; $f > 5 and print'
0
source

All Articles