Splunk Search

How to extract the field by using regex?

Peru123
Loves-to-Learn

 

Hi , I need to extract the value FISOBPIT10101 from the below lines.

 

message:PSUS7|8897|FISOBPIT10101|OWA|8897|8897|SignOnID|SPT|adding routing key in producer

Labels (1)
0 Karma

yuanliu
SplunkTrust
SplunkTrust

Depending on whether the leading phrase "message" and the trailing phrases such as "adding routing key in producer" are important, you can use rex or just 

  • If those phrases are unimportant, use split.  It is more efficient.

 

| eval of_interest = mvindex(split(your_field, "|"), 2)

 

  • If the first phrase and the last are important,

 

| rex field=your_field "message:(\d+|){2}(?<of_interest>\w+)(|\d+){5}|adding routing key in producer"​

 

Tags (3)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| rex "([^|]+\|){2}(?<field>[^|]+)"

https://regex101.com/r/UTPJb4/1

 

Peru123
Loves-to-Learn

Hi , I need this value only FISOBPIT10101

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| rex "([^|]+\|){2}(?<field>FISOBPIT10101)"
0 Karma

StefanoA
Explorer

You could go with | erex , if you're not expert with RegExs.

Otherwise, assuming the value is always in that position and not assuming a specific set of alphanumeric values, go with the following (13 steps per log, very efficient)

| rex field=<yourFieldOr_raw> "^(?:[^\|\v]*+\|){2}(?<yourValue>[^\|\v]*)"

 

0 Karma
Get Updates on the Splunk Community!

Enter the Splunk Community Dashboard Challenge for Your Chance to Win!

The Splunk Community Dashboard Challenge is underway! This is your chance to showcase your skills in creating ...

.conf24 | Session Scheduler is Live!!

.conf24 is happening June 11 - 14 in Las Vegas, and we are thrilled to announce that the conference catalog ...

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...