Splunk Search

How can I extract just a section of a field?

mark_groenveld
Path Finder

I have a key called message

Inside the value are several results but I need to only extract one result in the middle of the results.

Sample:
message:  template: 1234abcd, eeid: 5678efgh, consumerid: broker

My rex is below but returns the template value but also the results for eeid  and consumerid when I only need the template value of 1234abcd.

| rex field=message "template: (?<TemplateID>[^-]+)"

Labels (1)
0 Karma
1 Solution

dtburrows3
Builder

I think this regex will capture just the value for template.

\s+template:\s+([^,]+)


The character after the carrot inside the square brackets means match on a character not in this list.
And adding a "+" after is a quantifier for 1 or more times. 

So doing "template: (?<TemplateID>[^-]+)" is matching on all characters after 'template: ' up until a "-" (which I dont see one in the example. So replacing the "-" with a "," I think will extract the value as intended.

dtburrows3_0-1703012277428.png

 




View solution in original post

dtburrows3
Builder

I think this regex will capture just the value for template.

\s+template:\s+([^,]+)


The character after the carrot inside the square brackets means match on a character not in this list.
And adding a "+" after is a quantifier for 1 or more times. 

So doing "template: (?<TemplateID>[^-]+)" is matching on all characters after 'template: ' up until a "-" (which I dont see one in the example. So replacing the "-" with a "," I think will extract the value as intended.

dtburrows3_0-1703012277428.png

 




mark_groenveld
Path Finder

That worked.  Thanks dtburrows3!

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...