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!

Upcoming Webinar: Unmasking Insider Threats with Slunk Enterprise Security’s UEBA

Join us on Wed, Dec 10. at 10AM PST / 1PM EST for a live webinar and demo with Splunk experts! Discover how ...

.conf25 technical session recap of Observability for Gen AI: Monitoring LLM ...

If you’re unfamiliar, .conf is Splunk’s premier event where the Splunk community, customers, partners, and ...

A Season of Skills: New Splunk Courses to Light Up Your Learning Journey

There’s something special about this time of year—maybe it’s the glow of the holidays, maybe it’s the ...