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
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...