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!

[Puzzles] Solve, Learn, Repeat: Character substitutions with Regular Expressions

This challenge was first posted on Slack #puzzles channelFor BORE at .conf23, we had a puzzle question which ...

Splunk Community Badges!

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

[Puzzles] Solve, Learn, Repeat: Matching cron expressions

This puzzle (first published here) is based on matching timestamps to cron expressions.All the timestamps ...