Splunk Search

How to extract a field using rex?

iamtrying
New Member

This is the string in the log

I 2019-05-23 18:22:38.984Z 7881 216 XObk7A6CU-I62gr3UIKfXQAAAAs 1@43465473@A WPB-Log: file=/users/aa/test.cls method=fetchdata ID=Qwe123

I want to extract a field marked as bold to build a table.
Please note that all strings are variable so the rex should be generic.

Thanks for the help!

0 Karma
1 Solution

dmarling
Builder

Assuming that data is always in the same place this should grab it:

| rex "\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}Z \d+ \d+ (?<fieldName>[^\s]+)"

You'll need to choose the field name you want and replace fieldName with whatever you want to label that field. Here's a link to regex 101 that shows it working on the single example you provided: https://regex101.com/r/TdkzcA/1

If this comment/answer was helpful, please up vote it. Thank you.

View solution in original post

0 Karma

somesoni2
SplunkTrust
SplunkTrust

Give this a try (assuming the value you want to extract is 6th element from the start)

your base search
| rex "^(\S+\s+){5}(?<YourField>\S+)"
0 Karma

iamtrying
New Member

It worked too

0 Karma

dmarling
Builder

Assuming that data is always in the same place this should grab it:

| rex "\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3}Z \d+ \d+ (?<fieldName>[^\s]+)"

You'll need to choose the field name you want and replace fieldName with whatever you want to label that field. Here's a link to regex 101 that shows it working on the single example you provided: https://regex101.com/r/TdkzcA/1

If this comment/answer was helpful, please up vote it. Thank you.
0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

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

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...