简体   繁体   English

计算/枚举按内容过滤的文件夹中的文件

[英]Count/Enumerate files in folder filtered by content

I have a folder with lots of files with some data. 我有一个包含大量文件和一些数据的文件夹。 Not every file has a complete data set. 并非每个文件都有完整的数据集。 The complete data sets all have a common string of the form 'yyyy-mm-dd' on the last line so i thought i might filter with something like tail -n 1 , but have no idea how to do that. 完整的数据集在最后一行都有一个'yyyy-mm-dd'形式的公共字符串,所以我想我可能会使用tail -n 1这样的过滤器,但不知道如何做到这一点。

Any idea how to do something like that in a simple script or bash command? 知道如何在简单的脚本或bash命令中做这样的事情吗?

for f in *
do
    tail -n 1 "$f" |
    grep -qE '^[0-9]{4}-[01][0-9]-[0-3][0-9]$' &&
    echo "$f"
done

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 逐个打印每个子文件夹的文件数 - print the count of files for each sub folder iterativly linux bash计数文件夹中文件的大小 - linux bash count size of files in folder 结合greps以使脚本对文件夹中的文件进行计数 - Combining greps to make script to count files in folder 如何在不使用Bash脚本的情况下递归地获取包含工作文件夹的文件夹中多个扩展名过滤的所有文件 - How to recursively get all files filtered by multiple extensions within a folder including working folder without using find in Bash script 在 GCS 中获取文件数和文件夹总大小的最快方法? - Fastest way to get the files count and total size of a folder in GCS? 获取特定日期戳后进入UNIX文件夹的文件数 - Get the count of files coming in UNIX folder after certain datestamp 如何为linux中的文件夹生成清单(文件列表及其大小和数量) - How to generate manifest (List of files with their sizes and count) for a folder in linux Linux:计算名称和内容中包含单词的文件 - Linux: count files that contains a word in its name and content 如何复制使用 grep 过滤的文件 - How to copy files filtered with grep 如何使用名称中的计数将不同文件夹中的所有文件重命名为另一个文件夹? - How to rename all the files across different folders into another folder using count in the name?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM