Search class names in jars

May 19, 2013 in answer

0 votes, 0.00 avg. rating (0% score)

ANSWER:

You passed the -l option, telling grep to only list the file names. That’s the names of the .jar files, there are no other files involved.

If you want grep to output the class names, you need to remove -l. But that will print a lot of other junk on the same “line”, because the jars are binary files, not organized by lines. (With GNU grep, you need to pass -a to get that output and not just “Binary file … matches”.)

With GNU grep, one possibility is to match the full class name and pass -o to output just that:

grep -rao --include='*.jar' '[0-9A-Z_a-z]*SignonEJB[0-9A-Z_a-z]*' .

or if you want the packages as well

grep -rao --include='*.jar' '[$./0-9A-Z_a-z]*SignonEJB[0-9A-Z_a-z]*' .

Another approach is to run strings on the files first to extract printable strings.

find . -name '*.jar' -exec sh -c 'strings "$0" | grep SignonEJB | sed "s/^/$0:/"' {} ;

Gilles from http://unix.stackexchange.com/questions/76363