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