[英]find files that have number in file name greater than
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? 如果我有10个名为01-a.txt,02-a.txt,... 10-a.txt的文件 - 我怎样才能找到数字大于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. 谢谢。
You may use seq
for that, but it works only if all files have same naming convention: 您可以使用
seq
,但仅当所有文件具有相同的命名约定时它才有效:
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
It will cat all files named as "< numeric_value >-< rest >" and having this < numeric_value > greater than $LIM
. 它将捕获名为“<numeric_value> - <rest>”的所有文件,并使此<numeric_value>大于
$LIM
。
Even if they are written with one single digit (like 5 ), with two digits (like 05 ), or more... 即使它们是用一个数字(如5 ),两个数字(如05 )或更多...
And even if the < rest > are different among the files. 即使<rest>在文件中不同。
LIM=5
for file in $(ls);
do
number=$(echo $file | cut -f1 -d'-');
[ $number -gt $LIM ] && cat $file >> bigfile.txt;
done
Assuming the folder contains only these files. 假设文件夹仅包含这些文件。
This would list all files where the number is > 5 这将列出数字> 5的所有文件
ls [0-9]* | ls [0-9] * | awk -F '-' '{if ($1 > 5) print $0}'
awk -F' - ''{if($ 1> 5)打印$ 0}'
ls *.txt | perl -n -e '$f = $_; $f =~ s/\D//g; $f > 5 and print'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.