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
Engager

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!

Admin Your Splunk Cloud, Your Way

Join us to maximize different techniques to best tune Splunk Cloud. In this Tech Enablement, you will get ...

Cloud Platform | Discontinuing support for TLS version 1.0 and 1.1

Overview Transport Layer Security (TLS) is a security communications protocol that lets two computers, ...

New Customer Testimonials

Enterprises of all sizes and across different industries are accelerating cloud adoption by migrating ...