Splunk Search

Identifying Multiple fields with REGEX

DerekKing
Path Finder

Hi,

I have a field in the form of;
Key - Value | Key - Value | Key - Value
eg
Derek - 99.00 | Dave - 114.00 | Paul - 89.00

What I would like to do is, extract using a regex all keys and values into different field names.
eg
field1=Derek
value1=99.00
field2=Dave
value2=114.00

The data I need to break out can have between 1 and 10 fields separated by the pipe "|" symbol.

Does anyone know of an elegant regex to pull these fields out? Obviously the pipe symbol is optional at the end of the fields, as I dont know when i've reached the end of the data.

NOTE: I cannot use mvindex (and/or split), as they are running way too slow for the data, so i'm trialling a Regex to speed things up.

So Far, I have this as a concept, but i'm feeling like it's not the best way to attack this.

((?[A-z.]+) - (?\d+.\d+)( | ))((?[A-z.]+) - (?\d+.\d+)( | ))

Any guiding light - much appreciated.
Derek

0 Karma

landen99
Motivator
(?P<field1>\w*)\s*-\s*(?P<value1>[\d\.]*)\s*\|\s*(?P<field2>\w*)\s*-\s*(?P<value2>[\d\.]*)\s*\|\s*(?P<field3>\w*)\s*-\s*(?P<value3>[\d\.]*)
0 Karma

kristian_kolb
Ultra Champion

Or perhaps, to do it in the config files so that it won't clutter up your search query:

props.conf

[your_sourcetype]
REPORT-blah = pipedash

transforms.conf

[pipedash]
DELIMS = "|", "-"

See the docs:
http://docs.splunk.com/Documentation/Splunk/6.2.0/Admin/Transformsconf

/K

The really long version on is also in the docs:
http://docs.splunk.com/Documentation/Splunk/6.2.0/Knowledge/Createandmaintainsearch-timefieldextract...

0 Karma

dave_vgc
Engager

Hi Derek

You could possibly use a regex pattern that would result in 2 mv fields - something like

... |  rex field=origField "(?P<f1>\b[^-]+)\s-\s(?P<f2>\d+\.\d+)" max_match=10 | table origField f1 f2

alacercogitatus
SplunkTrust
SplunkTrust

You can use the extract command. http://docs.splunk.com/Documentation/Splunk/6.2.0/SearchReference/Extract

<your_search> | extract pairdelim=" | " kvdelim=" - "

This will pull your data into:

Derek=99.00
Dave=114.00
Paul=89.00
Get Updates on the Splunk Community!

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...