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

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, Karma 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
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

Thats_my_usrnme
Explorer

Hello its so usefull. Thanks for the query . I have a question for this subject. I have a FieldA and this fileds like a FieldA="a\b\c\n\....\z" . its a long field. I want it to automatically split the field and give each value a name. so I actually want to see a manual version of field transforms. If you have an idea and would like to help, I would be glad.

0 Karma

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
Get Updates on the Splunk Community!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...