Splunk Search

How split up a string into multiple fields

Motivator

Hi,

let's say there is a field like this:

FieldA = product.country.price

Is it possible to extract this value into 3 different fields?

FieldB=product
FieldC=country
FieldD=price

Thanks in advance

Heinz

1 Solution

SplunkTrust
SplunkTrust

Following could be the option your can use:(assuming delimiter is dot "." between field values)

REX command

 your base search | rex field=FieldA "(?<FieldB>.*)\.(?<FieldC>.*)\.(?<FieldD>.*)"

Split command

your base search | eval temp=split(FieldA,".") | eval FieldB=mvindex(temp,0)| eval FieldC=mvindex(temp,1)| eval FieldD=mvindex(temp,2) | fields - temp

View solution in original post

New Member

We have similar scenario but we have many domains and we want to split it accordingly . Any advice would be great help

testcorp1osb_tid
-> product: osb
-> environment: tid
-> region: test
-> segment: corp

procosbtid
-> product: osb
-> environment: tid
-> region: us
-> segment: proc

cvsbpeltid
-> product: bpel
-> environment: tid
-> region: us
-> segment: cvs

0 Karma

Motivator

Do you have a "region" in your string in the examples 2 & 3?

0 Karma

Motivator

Did you get an answer to this?

0 Karma

SplunkTrust
SplunkTrust

Here's one way to do it at search time:

... | rex field=FieldA "(?<FieldB>[^\.]*)\.(?<FieldC>[^\.]*)\.(?<FieldD>[\S]*)"
---
If this reply helps you, an upvote would be appreciated.

I know, 5 years later but I need this to separate multiple fields delim by :
This working swimmingly for what I needed

0 Karma

SplunkTrust
SplunkTrust

Following could be the option your can use:(assuming delimiter is dot "." between field values)

REX command

 your base search | rex field=FieldA "(?<FieldB>.*)\.(?<FieldC>.*)\.(?<FieldD>.*)"

Split command

your base search | eval temp=split(FieldA,".") | eval FieldB=mvindex(temp,0)| eval FieldC=mvindex(temp,1)| eval FieldD=mvindex(temp,2) | fields - temp

View solution in original post

Path Finder

In line to the same above scenario, what if the values in the fields are not even? like FieldA has the following values,
product.country
product
product.country.price
product.price
product.country.price
in the above scenario, i tried split, but it is not working (but works). how to quantify for missing values/null values? i couldn't quantify for null values in the fields.

0 Karma

Motivator

Try this:

your query |rex "FieldA\=(?<FieldB>.*)\.(?<FieldC>.*)\.(?<FieldD>.*)"|table FieldA FieldB FieldC FieldD

Lp

0 Karma