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!

Strengthen Your Future: A Look Back at Splunk 10 Innovations and .conf25 Highlights!

The Big One: Splunk 10 is Here!  The moment many of you have been waiting for has arrived! We are thrilled to ...

Now Offering the AI Assistant Usage Dashboard in Cloud Monitoring Console

Today, we’re excited to announce the release of a brand new AI assistant usage dashboard in Cloud Monitoring ...

Stay Connected: Your Guide to October Tech Talks, Office Hours, and Webinars!

What are Community Office Hours? Community Office Hours is an interactive 60-minute Zoom series where ...