i'm learning bash script by doing, and i had to find files which don't contain a certain string and the command i came up with didn't work. I solved the problem in the meantime by using grep -L (stackoverflow.com/questions/1748129/), but i would still want to know, what's wrong with my original command (so i can learn for the future).
the command is:
find path/ -name *.log -print0 | xargs -0 -i sh -c "if [ '1' == $(cat {} | grep -c 'string that should not occur') ]; then echo {}; fi"
and the error
cat: {}: No such file or directory
I also tried without 'sh -c' before, but it didn't work either.
edit: I also tried
find ./path -name *.log -print0 | xargs -0 -i bash -c "if [ '0' == $(cat $0 | grep -c \"ren0 \[RenderJob\] Render time:\") ]; then echo $0; fi" {}
which didn't work because of https://stackoverflow.com/a/1711985/4032670
You can use find
and xargs
like this:
find path/ -name '*.log' -print0 |
xargs -r0 -I {} bash -c 'grep -q "string that should not occur" "{}" || echo "{}"'
Without bash -c
you can do this using grep -L
:
find path/ -name '*.log' -print0 |
xargs -r0 grep -L "string that should not occur"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With