I’ve found many examples on how to search for files that exist in a jar, but I want to find text that exists in a file that exists in a jar. How can I do this without unpacking all of my jar files?
#!/bin/sh
LOOK_FOR="string to find inside a file inside a jar"
for i in `find . -name "*jar"`
do
echo "Looking in $i ..."
jar tvf $i | grep $LOOK_FOR > /dev/null
if [ $? == 0 ]
then
echo "==> Found \"$LOOK_FOR\" in $i"
fi
done
If you just want to see if any of the file in the jar contains a specific string (
$LOOK_FOR), but don’t care about which file, you can do this withunzip, here’s a small test:With the
-poption, the files are unzipped to pipe (stdout).If you want to know in which file the string is, I don’t think you can do anything better than unpack.