Created
February 8, 2018 09:22
-
-
Save lefou/6696ff5f0e1bd9c18e95291eec873128 to your computer and use it in GitHub Desktop.
Find JAR files and searches their content listings for a given pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Default behavior is scan directory recursively | |
if [ "x$1" == "x" ]; then | |
echo "Find JAR files and searches their content listings for a given pattern" | |
echo | |
echo "Usage: jarfind [-l] <SEARCHTERM> [[DIR] ...]" | |
echo | |
echo "If DIRs is empty, $HOME/.m2/repository is searched." | |
exit 0 | |
fi | |
if [ "x$1" = "x-l" ] ; then | |
ONLY_FILES=1 | |
shift | |
fi | |
SEARCH="$1" | |
shift | |
if [ "x$1" = "x" ]; then | |
JARS="$(find $HOME/.m2/repository -iname \*\.jar)" | |
else | |
JARS="" | |
for i in $* ; do | |
JARS="$JARS $(find $i -iname \*\.jar)" | |
done | |
fi | |
for i in $JARS; do | |
RESULT="$(unzip -l $i | grep -i $SEARCH)" | |
if [ "x$RESULT" != "x" ] ; then | |
echo Jarfile: $i | |
if [ "x${ONLY_FILES}" != "x1" ] ; then | |
# we rerun the search command to have colored output fronm grep | |
unzip -l $i | grep --color -i $SEARCH | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment