forked from oldratlee/useful-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
find-in-jars.sh
executable file
·53 lines (47 loc) · 1.07 KB
/
find-in-jars.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
# @Function
# Find file in the jar files under current directory
#
# @Usage
# $ find-in-jars.sh log4j\\.xml
# $ find-in-jars.sh 'log4j\.properties'
# $ find-in-jars.sh 'log4j\.properties|log4j\.xml'
#
# @author Jerry Lee
PROG=`basename $0`
usage() {
cat <<EOF
Usage: ${PROG} [OPTION]... PATTERN
Find file in the jar files under specified directory(recursive, include subdirectory)
Example: ${PROG} -d libs 'log4j\.properties$'
Options:
-d, --dir the directory that find jar files
-h, --help display this help and exit
EOF
exit $1
}
ARGS=`getopt -a -o d:h -l dir:,help -- "$@"`
[ $? -ne 0 ] && usage 1
eval set -- "${ARGS}"
while true; do
case "$1" in
-d|--dir)
dir="$2"
shift 2
;;
-h|--help)
usage
;;
--)
shift
break
;;
esac
done
[ -z "$1" ] && { echo No find file pattern! ; usage 1; }
dir=${dir:-.}
find ${dir} -iname '*.jar' | while read jarFile; do
jar tf ${jarFile} | egrep "$1" | while read file; do
echo "${jarFile}"\!"${file}"
done
done