find/grep 管道中的否定搜索不会删除任何记录

find/grep 管道中的否定搜索不会删除任何记录

我在使用 bash find 命令时遇到了一些困难。

问题是一个迟到的要求,它希望我从包含 *.appstrng 的 *.app 文件中删除所有记录”

这是我最初的查找管道,它运行完美,没有负面尝试剥离记录:

find . -type f -iname "*.app" -exec grep -we selected_apps -e app_name --color=auto --with-filename {}         \; > LOG.txt

现在,这是我在创建 LOG.txt 之前添加 .appstring 剥离的一些尝试

1)使用 grep -v

find . -type f -iname "*.app" -exec grep -we selected_apps -e app_name -ev "*.appstring" --color=auto --with-filename {} \; > LOG.txt

2)使用 awk

find . -type f -iname "*.app" -exec grep -we selected_apps --color=auto --with-filename {} \; | awk '!/*.appstring/' > LOG.txt

我不确定 find/grep 或 find/awk 是否会以这种方式工作...欢迎所有评论!谢谢!!

答案1

您可以使用原始命令并使用附加命令删除一些结果:

cat LOG.txt | while read FILE; do
    if ! grep -q "*.appstring" "$FILE"; then
        echo $FILE >> LOG-filtered.txt
    fi
done

相关内容