Spaces:
Build error
Build error
Update detection_ja.sh
Browse files- detection_ja.sh +8 -14
detection_ja.sh
CHANGED
@@ -6,28 +6,23 @@ extensions="js|mjs|jsx|json|txt|html|htm|json5|md|css"
|
|
6 |
# 一時ファイル
|
7 |
TMP_RESULT=$(mktemp)
|
8 |
|
9 |
-
# エンコーディングを自動判定して UTF-8 に変換して処理
|
10 |
find . -type f -regextype posix-extended -regex ".*\.($extensions)$" | while read -r file; do
|
11 |
-
# 自動判定(fileコマンドで文字コード取得)
|
12 |
encoding=$(file -bi "$file" | sed -n 's/.*charset=\(.*\)$/\1/p')
|
13 |
|
14 |
-
# UTF-8 に変換できなければスキップ
|
15 |
if ! iconv -f "$encoding" -t UTF-8 "$file" > /dev/null 2>&1; then
|
16 |
continue
|
17 |
fi
|
18 |
|
19 |
-
# UTF-8に変換して内容読み込み
|
20 |
content=$(iconv -f "$encoding" -t UTF-8 "$file")
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
|
30 |
-
# 結果がある場合だけ出力に追加
|
31 |
if [[ -n "$matches" ]]; then
|
32 |
echo "\"$file\": {" >> "$TMP_RESULT"
|
33 |
echo "$matches" | while read -r line; do
|
@@ -39,7 +34,7 @@ find . -type f -regextype posix-extended -regex ".*\.($extensions)$" | while rea
|
|
39 |
fi
|
40 |
done
|
41 |
|
42 |
-
# JSON
|
43 |
if [[ -s "$TMP_RESULT" ]]; then
|
44 |
echo "{"
|
45 |
sed '$ s/,$//' "$TMP_RESULT"
|
@@ -48,5 +43,4 @@ else
|
|
48 |
echo "{}"
|
49 |
fi
|
50 |
|
51 |
-
# 後始末
|
52 |
rm "$TMP_RESULT"
|
|
|
6 |
# 一時ファイル
|
7 |
TMP_RESULT=$(mktemp)
|
8 |
|
|
|
9 |
find . -type f -regextype posix-extended -regex ".*\.($extensions)$" | while read -r file; do
|
|
|
10 |
encoding=$(file -bi "$file" | sed -n 's/.*charset=\(.*\)$/\1/p')
|
11 |
|
|
|
12 |
if ! iconv -f "$encoding" -t UTF-8 "$file" > /dev/null 2>&1; then
|
13 |
continue
|
14 |
fi
|
15 |
|
|
|
16 |
content=$(iconv -f "$encoding" -t UTF-8 "$file")
|
17 |
|
18 |
+
matches=$(echo "$content" | perl -CS -ne '
|
19 |
+
while (/([\p{Hiragana}\p{Katakana}\p{Han}a-zA-Z0-9ー]+(?:[\p{Hiragana}\p{Katakana}\p{Han}a-zA-Z0-9ー]+)*)/g) {
|
20 |
+
my $word = $1;
|
21 |
+
# 日本語を含むものだけ出力
|
22 |
+
print "$word\n" if $word =~ /[\p{Hiragana}\p{Katakana}\p{Han}]/;
|
23 |
+
}
|
24 |
+
' | sort | uniq)
|
25 |
|
|
|
26 |
if [[ -n "$matches" ]]; then
|
27 |
echo "\"$file\": {" >> "$TMP_RESULT"
|
28 |
echo "$matches" | while read -r line; do
|
|
|
34 |
fi
|
35 |
done
|
36 |
|
37 |
+
# JSON出力
|
38 |
if [[ -s "$TMP_RESULT" ]]; then
|
39 |
echo "{"
|
40 |
sed '$ s/,$//' "$TMP_RESULT"
|
|
|
43 |
echo "{}"
|
44 |
fi
|
45 |
|
|
|
46 |
rm "$TMP_RESULT"
|