Splunk Search

How to split up a string into multiple fields?

HeinzWaescher
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

Labels (1)
1 Solution

somesoni2
Revered Legend

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

pavan_bhumanapa
New Member

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

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

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

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

0 Karma

HeinzWaescher
Motivator

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

0 Karma

robertlynch2020
Motivator

Did you get an answer to this?

0 Karma

richgalloway
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.

aebrittingham
Engager

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

0 Karma

somesoni2
Revered Legend

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

sundarrajan
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

lpolo
Motivator

Try this:

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

Lp

0 Karma