linux - 带有数字扩展名的 Grep 文件

标签 linux bash grep

考虑一个包含 20 个文件的目录,编号如下:

ll *test*
> test.dat
> test.dat.1
> test.dat.2
...
> test.dat.20

可以通过

找到与给定日期匹配的文件子集
ll *test* | grep "Sep 29"
> test.dat
> test.dat.1
> test.dat.2

如何在该文件子集中搜索线条图案?我想在上述三个文件的每一行中 grep 查找字符串 WARNING 。我如何告诉 grep 将其搜索限制为仅此子集?

最佳答案

-l 选项的用途是:列出匹配的文件

-L 选项的作用相反:列出不匹配的文件

grep WARNING $(grep -l "Sep 29" *test.dat*)

编辑

我误解了这个问题:你不想在已经包含“Sep 29”的文件上 grep“WARNING”,你想在最后一次修改于 Sep 29 的文件上 grep“WARNING”。

因此我建议:

grep WARNING $(ll *test.dat* | grep "Sep 29")

但我不会依赖ll输出。

关于linux - 带有数字扩展名的 Grep 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46488128/

相关文章:

bash - 当存在空字符且使用 -z 选项时,Grep 不起作用

linux - 计算包含特定字符的文本文件中的行数(Linux)?

c - 将变量传递给 C 中的系统函数

python - 执行 Linux 命令并获取 PID

javascript - 无法运行 Node app.js 文件

linux bash : line 18: syntax error near unexpected token `fi' Q2. sh:第 18 行: `fi'

linux - 根据文件名条件复制文件

java - 如何在 C 中实现注解?

bash - Vim 不突出显示 bash 脚本的语法(msysgit 版本)

linux - 使用 ls 递归打印完整目录树的 Shell 脚本