Spaces:
Runtime error
Runtime error
Update detection_ja.sh
Browse files- detection_ja.sh +12 -9
detection_ja.sh
CHANGED
@@ -1,17 +1,22 @@
|
|
1 |
#!/bin/bash
|
2 |
|
3 |
-
#
|
4 |
-
extensions="js|mjs|jsx|json|txt|html|htm"
|
5 |
|
6 |
# 一時ファイル
|
7 |
TMP_RESULT=$(mktemp)
|
8 |
|
9 |
-
#
|
10 |
find . -type f -regextype posix-extended -regex ".*\.($extensions)$" | while read -r file; do
|
11 |
-
#
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
13 |
perl -CSD -pe '
|
14 |
-
#
|
15 |
s/([^\p{Han}\p{Hiragana}\p{Katakana}a-zA-Z]+)/\n/g;
|
16 |
s/^\s+|\s+$//g;
|
17 |
' | grep -P '[\p{Hiragana}\p{Katakana}\p{Han}]' | sort | uniq)
|
@@ -22,13 +27,12 @@ find . -type f -regextype posix-extended -regex ".*\.($extensions)$" | while rea
|
|
22 |
escaped=$(echo "$line" | sed 's/"/\\"/g')
|
23 |
echo " \"$escaped\": []," >> "$TMP_RESULT"
|
24 |
done
|
25 |
-
# 最後のカンマを削除してオブジェクトを閉じる
|
26 |
sed -i '$ s/,$//' "$TMP_RESULT"
|
27 |
echo "}," >> "$TMP_RESULT"
|
28 |
fi
|
29 |
done
|
30 |
|
31 |
-
#
|
32 |
if [[ -s "$TMP_RESULT" ]]; then
|
33 |
echo "{"
|
34 |
sed '$ s/,$//' "$TMP_RESULT"
|
@@ -37,5 +41,4 @@ else
|
|
37 |
echo "{}"
|
38 |
fi
|
39 |
|
40 |
-
# 一時ファイル削除
|
41 |
rm "$TMP_RESULT"
|
|
|
1 |
#!/bin/bash
|
2 |
|
3 |
+
# 対象拡張子
|
4 |
+
extensions="js|mjs|jsx|json|txt|html|htm|json5|md|css"
|
5 |
|
6 |
# 一時ファイル
|
7 |
TMP_RESULT=$(mktemp)
|
8 |
|
9 |
+
# 検出処理
|
10 |
find . -type f -regextype posix-extended -regex ".*\.($extensions)$" | while read -r file; do
|
11 |
+
# UTF-8 に変換して読み取り(iconvで変換、読めなければスキップ)
|
12 |
+
content=$(iconv -f UTF-8 -t UTF-8 "$file" 2>/dev/null)
|
13 |
+
if [[ -z "$content" ]]; then
|
14 |
+
continue
|
15 |
+
fi
|
16 |
+
|
17 |
+
matches=$(echo "$content" | grep -oE '[^[:space:][:cntrl:]]*[\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Han}a-zA-Z]*[\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Han}]+[^[:space:][:cntrl:]]*' | \
|
18 |
perl -CSD -pe '
|
19 |
+
# スペースや記号で分割(日本語のまとまりを維持)
|
20 |
s/([^\p{Han}\p{Hiragana}\p{Katakana}a-zA-Z]+)/\n/g;
|
21 |
s/^\s+|\s+$//g;
|
22 |
' | grep -P '[\p{Hiragana}\p{Katakana}\p{Han}]' | sort | uniq)
|
|
|
27 |
escaped=$(echo "$line" | sed 's/"/\\"/g')
|
28 |
echo " \"$escaped\": []," >> "$TMP_RESULT"
|
29 |
done
|
|
|
30 |
sed -i '$ s/,$//' "$TMP_RESULT"
|
31 |
echo "}," >> "$TMP_RESULT"
|
32 |
fi
|
33 |
done
|
34 |
|
35 |
+
# JSON出力
|
36 |
if [[ -s "$TMP_RESULT" ]]; then
|
37 |
echo "{"
|
38 |
sed '$ s/,$//' "$TMP_RESULT"
|
|
|
41 |
echo "{}"
|
42 |
fi
|
43 |
|
|
|
44 |
rm "$TMP_RESULT"
|