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!

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...