jenny jenny - 5 months ago 10
Linux Question

How to find jar does not have a given string in linux

I want to get list of jars which are not having a particular string in their classes.
I used the following command for getting string "hello" matched jars.

find . -iname '*.jar' -printf "unzip -c %p | grep -q 'hello' && echo %p\n" | sh.

So I tried by putting the following command for not getting "hello" matched jars, which is not working.

find . -iname '*.jar' -printf "unzip -c %p |!( grep -q 'hello') && echo %p\n" | sh

Answer

Basically you may just change && to || operator:
find . -iname '*.jar' -printf "unzip -c %p | grep -q 'hello' || echo %p\n" | sh.

AND and OR lists are sequences of one of more pipelines separated by the && and || control operators, respectively. AND and OR lists are executed with left associativity.
An AND list has the form

          command1 && command2

command2 is executed if, and only if, command1 returns an exit status of zero.

An OR list has the form

          command1 || command2

command2 is executed if and only if command1 returns a non-zero exit status. The return status of AND and OR lists is the exit status of the last command executed in the list.