forked from shaoshuai0102/properties-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.sh
executable file
·44 lines (38 loc) · 1.09 KB
/
parser.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
#!/bin/bash
# eg. ./parser.sh assets.url antx.properties
# eg. cat antx.properties | ./parser.sh assetsServer.url
set -e
target=$1
findStr()
{
local target=$1
local file=$2
#echo target : $target
#echo file : $file
sed '/^\#/d' ${file} | grep ${target} | sed -e 's/ //g' |
while read LINE
do
local KEY=`echo $LINE | cut -d "=" -f 1`
local VALUE=`echo $LINE | cut -d "=" -f 2`
[ ${KEY} == ${target} ] && {
local UNKNOWN_NAME=`echo $VALUE | grep '\${.*}' -o | sed 's/\${//' | sed 's/}//'`
if [ $UNKNOWN_NAME ];then
local UNKNOWN_VALUE=`findStr ${UNKNOWN_NAME} ${file}`
echo ${VALUE} | sed s/\$\{${UNKNOWN_NAME}\}/${UNKNOWN_VALUE}/
else
echo $VALUE
fi
return
}
done
return
}
if [ $2 ];then
findStr ${target} $2
else
while read data; do
echo ${data} >> .__tmpfile19890102_
done
findStr ${target} .__tmpfile19890102_
rm -f .__tmpfile19890102_
fi