-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollectKeywords
More file actions
executable file
·70 lines (62 loc) · 1.67 KB
/
collectKeywords
File metadata and controls
executable file
·70 lines (62 loc) · 1.67 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#! /bin/bash
#文件名: collectKeywords -p = [path]; -f = [fileTypes]/[from]; -r = [regularExpressionOfKeywords]; -t = [targetFileName]/[to];
#从文件中,分析出用到的Keywords。
#example: collectKeywords -p ~/Workspace/KCCS_V13/CODE/webapp/page/desktopAdmin/ -f "*.js" -t "js.js"
LC_ALL=C
## startDefault Value
regularExp="[0-9]\{8\}"
## endDefault Value
## startRegion Option
while getopts "p:t:r:f:" optname
do
case "$optname" in
"p")
path=$OPTARG
;;
"t")
fileTypes=$OPTARG
;;
"r")
regularExp=$OPTARG
;;
"f")
targetFileName=$OPTARG
;;
"?")
echo "unknown option $OPTARG"
;;
":")
echo "No argument value for option $OPTARG"
;;
*)
## should not occur
echo "unknown error while processing options"
;;
esac
done
## endRegion Option
## collect key words in folder
for fType in "$fileTypes"
do
echo "$fType"
#this will get file name
#find $path -name "$fType" -exec grep -isoh --exclude=*.swp --exclude=*.git* --exclude=*.svn* --color=auto "${regularExp}" {} \; -print >> ${targetFileName} #with found file names
grep ${regularExp} -isorh --include=${fType} ${path} >> ${targetFileName}
done
## remove repeated keywords
declare -a keywordAry=()
echo ${#keywordAry[@]}
IFS=" ";
while read keyword
do
tmpA=( ${keywordAry[@]/${keyword}/} )
if [ ${#tmpA[@]} -eq ${#keywordAry[@]} ];
then
keywordAry=(${keywordAry[@]} ${keyword})
else
echo ${keyword}" +1."
fi
done < ${targetFileName}
## write result to target file
echo ${keywordAry[@]}|tr " " "\n" > ${targetFileName}
vi ${targetFileName}