简体   繁体   English

查找文件名大于的文件

[英]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.

相关问题 Linux:如何获取名称以大于10的数字结尾的文件 - Linux: How to get files with a name that ends with a number greater than 10 Linux如何在文件名中列出大于特定时间戳的文件? - Linux How to List Files greater than particular timestamp in file name? 如何在 linux 中查找大于大小的文件 - How to find files greater than a size in linux 如何查找文件名中编号最大的文件 - How to find files with highest number in file name 查找名称中带有大于某个整数的整数的所有文件,最好在LINUX设置中 - Find all files with integers in the name that are greater than a certain value, preferably in a LINUX setting 如何在文件名长度大于255的JAR文件中打开文件? - How to open files in JAR file with filename length greater than 255? 查找名称小于1950的数字的文件名 - Find filenames with number in name lower than 1950 如何在 Linux 中找到大于给定数字的列中的元素数? - How do I find the number of elements in a column greater than a given number in Linux? 在bash中处理二进制数据文件,查找大于某个数字的元素 - Processing binary data files in bash, finding elements which are greater than some number 如何在 Linux 中找到大于特定数字的变量? - How can I find variable which greater than specific number in Linux?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM