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!

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...

Index This | Forward, I’m heavy; backward, I’m not. What am I?

April 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...