Search for a class or a pattern in jar files under a folder
searchJars.sh :
-----------------------------------------------------
#!/bin/bash
while getopts "n:il" optionName; do
case "$optionName" in
i) case_sensitive_op=-i;;
l) long_format=Y;;
n) search_expr="$OPTARG";;
[?]) echo "Usage: searchJars [-i] [-l] -n ";exit 1;;
esac
done
if [ -z $search_expr ]
then
echo "Usage: searchJars [-i] [-l] -n ";
exit 1;
fi
if [ $# -lt 1 ]
then
echo "Usage: searchJars [-i] [-l] -n ";
exit 1;
fi
REG_EXPR="$search_expr"
for i in `find . -name "*jar"`
do
jar tvf $i 2> /dev/null | grep $case_sensitive_op $REG_EXPR > /dev/null
if [ $? == 0 ]
then
echo $i
if [ "$long_format" = "Y" ]
then
jar tvf $i | grep $case_sensitive_op $REG_EXPR | awk '{ print " "$8}'
echo "-----------------------------------------------------"
fi
fi
done
-----------------------------------------------------
Usage:
Usage: searchJars [-i] [-l] -n CLASS_NAME_OR_EXPRESSION