小编Sai*_*Sai的帖子

有没有办法在带有选项exec的find命令中使用If条件?

场景:文件夹中有多个文件,我正在尝试查找特定的文件集,如果给定的文件有特定的信息,那么我需要grep信息.

例如:

find /abc/test \( -type f -name 'tst*.txt' -mtime -1 \) -exec grep -Po '(?<type1).*(?=type1|(?<=type2).*(?=type2)' {} \;
Run Code Online (Sandbox Code Playgroud)

我需要包括if条件和find -exec(如果grep为true则打印上面的内容)

if grep -q 'case=1' <filename>; then
    grep -Po '(?<type1).*(?=type1|(?<=type2).*(?=type2)'
fi
Run Code Online (Sandbox Code Playgroud)

谢谢

unix bash shell find

2
推荐指数
1
解决办法
154
查看次数

标签 统计

bash ×1

find ×1

shell ×1

unix ×1