Splunk Search

Extract field value

vintik
Engager

Hello,

Could anybody assist with this question - what method is the best to extract to new field value of "animal" key? Should I use eval or searchmatch or something else?

Here is example:

[some_date] ..."application":"some_app", "animal":"dog","segment":....
[some_date] ..."application":"some_app", "animal":"cat","segment":....

I need this variable to use in stats.

Tags (2)
0 Karma
1 Solution

FrankVl
Ultra Champion

This should work:
| rex "\"animal\":\"(?<animal>[^\"]+)\""

Alternatively, you could try the following to apply key value extractions on your events. Whether this works properly depends on what exactly your full data looks like, but might be worth playing around with.
| extract pairdelim=",", kvdelim=":"

View solution in original post

althomas
Communicator

If it's json, use spath

Otherwise you can do something like this:

transforms.conf:

[my_kv_transform]
FORMAT = $1::$2
REGEX = \"([^"]+)\":\"([^"]+)\"

props.conf

[my_sourcetype]
REPORT-my_sourcetype_kv = my_kv_transform

This should do search-time extractions to get animal=dog and application=someapp

0 Karma

FrankVl
Ultra Champion

This should work:
| rex "\"animal\":\"(?<animal>[^\"]+)\""

Alternatively, you could try the following to apply key value extractions on your events. Whether this works properly depends on what exactly your full data looks like, but might be worth playing around with.
| extract pairdelim=",", kvdelim=":"

Get Updates on the Splunk Community!

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

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

Combine Multiline Logs into a Single Event with SOCK: a Step-by-Step Guide for ...

Combine multiline logs into a single event with SOCK - a step-by-step guide for newbies Olga Malita The ...