gpt4 book ai didi

linux - 这个 bash 命令(find + xarg + grep)有什么问题?

转载 作者:太空狗 更新时间:2023-10-29 12:13:02 24 4
gpt4 key购买 nike

我边做边学 bash 脚本,我不得不找到不包含特定字符串的文件,而我想出的命令不起作用。我同时使用 grep -L (stackoverflow.com/questions/1748129/) 解决了这个问题,但我仍然想知道我原来的命令有什么问题(这样我可以为将来学习)。

命令是:

find path/ -name *.log -print0 | xargs -0 -i sh -c "if [ '1' == $(cat {} | grep -c 'string that should not occur') ]; then echo {}; fi"

错误

cat: {}: No such file or directory

我之前也尝试过不使用'sh -c',但它也没有用。

编辑:我也试过了

find ./path -name *.log -print0 | xargs -0 -i bash -c "if [ '0' == $(cat $0 | grep -c \"ren0 \[RenderJob\] Render time:\") ]; then echo $0; fi" {}

由于 https://stackoverflow.com/a/1711985/4032670 而无法正常工作

最佳答案

您可以像这样使用 findxargs:

find path/ -name '*.log' -print0 |
xargs -r0 -I {} bash -c 'grep -q "string that should not occur" "{}" || echo "{}"'

如果没有 bash -c,您可以使用 grep -L 执行此操作:

find path/ -name '*.log' -print0 |
xargs -r0 grep -L "string that should not occur"

关于linux - 这个 bash 命令(find + xarg + grep)有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35150242/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com