Splunk Search

ログの中から漢字やひらがなを抽出する方法は?

Splunk_Shinobi
Splunk Employee
Splunk Employee

ログの中のメッセージに含まれる日本語のカタカナのみ、漢字のみを抽出したい場合、正規表現等で抽出する方法はありますか?
形態素解析器を導入してもいいのですが、単純な単語抽出だけやりたい場合に簡単に実現する方法をさがしています。

Tags (1)
1 Solution

melonman
Motivator

.. | rex field=line max_match=100 "(?[\p{Hiragana}]+)"

などの正規表現ではいかがでしょうか。
以下、サンプルになります。

$  ./splunk search '| inputlookup jp.csv | head 2 | rex field=line max_match=100 "(?<word>\p{Han}+)"'

                                       line                                         word
----------------------------------------------------------------------------------- ----
splunk Enterpriseとは業界をリードする運用インテリジェンスのプラットフォーム                  業界
                                                                                    運用
ITシステムやテクノロジー基盤(Webサイト、アプリケーション、サーバー、ネットワーク、               基盤

$ ./splunk search '| inputlookup jp.csv | rex field=line max_match=100 "(?<word>[\p{Katakana}ー]+)" | top word'
         word          count  percent
---------------------- ----- ---------
マシンデータ               2 28.571429
ネットワーク               2 28.571429
トランザクション           2 28.571429
リード                     1 14.285714
リアルタイム               1 14.285714
モバイル                   1 14.285714
プラットフォーム           1 14.285714
トラブルシューティング     1 14.285714
テクノロジー               1 14.285714
センサー                   1 14.285714

View solution in original post

melonman
Motivator

.. | rex field=line max_match=100 "(?[\p{Hiragana}]+)"

などの正規表現ではいかがでしょうか。
以下、サンプルになります。

$  ./splunk search '| inputlookup jp.csv | head 2 | rex field=line max_match=100 "(?<word>\p{Han}+)"'

                                       line                                         word
----------------------------------------------------------------------------------- ----
splunk Enterpriseとは業界をリードする運用インテリジェンスのプラットフォーム                  業界
                                                                                    運用
ITシステムやテクノロジー基盤(Webサイト、アプリケーション、サーバー、ネットワーク、               基盤

$ ./splunk search '| inputlookup jp.csv | rex field=line max_match=100 "(?<word>[\p{Katakana}ー]+)" | top word'
         word          count  percent
---------------------- ----- ---------
マシンデータ               2 28.571429
ネットワーク               2 28.571429
トランザクション           2 28.571429
リード                     1 14.285714
リアルタイム               1 14.285714
モバイル                   1 14.285714
プラットフォーム           1 14.285714
トラブルシューティング     1 14.285714
テクノロジー               1 14.285714
センサー                   1 14.285714
Get Updates on the Splunk Community!

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...