-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommonName.sh
67 lines (59 loc) · 1.56 KB
/
commonName.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
# author:Mrright
# version:1.0
#
# 该脚本用于比较文件中是否存在相同的name,该文件中没组数据的格式为name=value,通过比较每组中的name来比较是否存在,如果存在则输出value;每组数据通过“#”分割
# 用法:通过$1传入name,$2传入文件名称
if [ "$1" == "" ] || [ "$2" == "" ];then
echo "parameter not enough!"
echo "need filename and match value"
exit
fi
data=`cat "$1"`
arrayIndex=0
while [ 0 -lt "${#data}" ]
do
splitIndex=`expr index "$data" "#"`
if [ 0 -eq "$splitIndex" ];then
matched=`compare.sh "$data" "$2"`
if [ "$matched" == "#illegal#" ];then
echo ""
elif [ "$matched" == "" ];then
newData[$arrayIndex]=$data
arrayIndex=`expr $arrayIndex + 1`
else
echo "$matched"
fi
break
else
strOff=`expr $splitIndex - 1`
dataCell=${data:0:$strOff}
if [ "$dataCell" == "" ];then
continue
fi
matched=`compare.sh "$dataCell" "$2"`
if [ "$matched" == "#illegal#" ];then
echo ""
elif [ "$matched" == "" ];then
newData[$arrayIndex]=$dataCell
arrayIndex=`expr $arrayIndex + 1`
else
echo "$matched"
fi
data=${data:$splitIndex}
fi
done
runIndex=0
userHome=`ls ~ -d`
# 刷新地址记录表
tabFile="$userHome/.recycleInfo/.recycleTable.tab"
while [ "$runIndex" -lt "$arrayIndex" ]
do
if [ "${#print}" -eq 0 ];then
print="${newData[$runIndex]}"
else
print="$print#${newData[$runIndex]}"
fi
runIndex=`expr $runIndex + 1`
done
printf "$print" > "$tabFile"