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
Get Updates on the Splunk Community!

Splunk Observability Cloud's AI Assistant in Action Series: Auditing Compliance and ...

This is the third post in the Splunk Observability Cloud’s AI Assistant in Action series that digs into how to ...

Splunk Community Badges!

  Hey everyone! Ready to earn some serious bragging rights in the community? Along with our existing badges ...

What You Read The Most: Splunk Lantern’s Most Popular Articles!

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...