-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathexclude-duplicates.sh
executable file
·93 lines (90 loc) · 1.89 KB
/
exclude-duplicates.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/sh
new="${1}"
out="${new}.out"
fallback="${2}"
default="${3}"
if [ -z "${new}" -o -z "${fallback}" -o -z "${default}" ]; then
echo "Usage:"
echo " $(basename $0) new_file fallback_file default_file"
echo "Example:"
echo " $(basename $0) MX.js ES.js default.js"
exit 1
fi
echo "===> Checking ${new}..."
cat ${new} | gawk "BEGIN {
fb = \"${fallback}\"
def = \"${default}\"
out = \"${out}\"
}"'{
if ($0 ~ "\"TODO: ") {
# Skip all TODOs
#print "T ", $0
} else if ($0 ~ "[.]en\":") {
# Check if english line match the default file
key = $1
val = $0
# Remove key
gsub(key, "", val)
# Remove leading spaces
gsub(/^\s+/, "", val)
# Remove .en suffix
gsub("[.]en\"", "\"", key)
# Ignore case and remove quotes
key = tolower(substr(key, 2, length(key) - 3))
val = tolower(substr(val, 2, length(val) - 3))
dup = 0
while (getline l < def) {
l = tolower(l)
if (index(l, key) && index(l, val)) {
dup = 1
break
}
}
close(def)
# if (!dup) {
# TODO: skip all english lines
if (false) {
#printf "EN key=[%s] val=[%s] l=[%s]\n", key, val, l
print $0 > out
}
} else if ($0 ~ /[ \t]*\"/) {
# Check if line match the fallback file
key = $1
val = $0
# Remove key
gsub(key, "", val)
# Remove leading spaces
gsub(/^\s+/, "", val)
# Remove .en suffix
gsub("[.]en\"", "\"", key)
# Ignore case and remove quotes
key = tolower(substr(key, 2, length(key) - 3))
val = tolower(substr(val, 2, length(val) - 3))
dup = 0
while (getline l < fb) {
l = tolower(l)
if (index(l, key) && index(l, val)) {
dup = 1
break
}
}
close(fb)
if (!dup) {
while (getline l < def) {
l = tolower(l)
if (index(l, key) && index(l, val)) {
dup = 1
break
}
}
close(def)
}
if (!dup) {
#printf "FB key=[%s] val=[%s] l=[%s]\n", key, val, l
print $0 > out
}
} else {
# Else just pass the line
print $0 > out
}
}'