Splunk Search

Data Model Columns and Rows Transpose using Eval

TreeHut
New Member

Hello-
How do you transpose columns inside the Data Model using eval?

My goal is to filter a column called column1 inorder to extract data from a second column called column2. A third column would be created to only hold vales transferred from the second column. The name of this column would be column3.

column1
filter1
filter2
filter3

column2
data1
data2
data3

column3
null
data2
null

This code pulls the value randomly:

|eval if(like(column1,"filter2"),column2,NULL)

Field Name = column3

I need to extract the value from column2 using the same row referenced in column1.

Thanks!

0 Karma
1 Solution

woodcock
Esteemed Legend

Like this:

|makeresults | eval _raw="column1='filter1 filter2 filter3' column2='data1 data2 data3'"
| kv
| foreach column* [ rex field=<<FIELD>> mode=sed "s/'//g" | makemv <<FIELD>> ]
| eval filter="filter2"
| eval column3 = mvindex(column2, mvfind(column1, filter))

View solution in original post

0 Karma

woodcock
Esteemed Legend

Like this:

|makeresults | eval _raw="column1='filter1 filter2 filter3' column2='data1 data2 data3'"
| kv
| foreach column* [ rex field=<<FIELD>> mode=sed "s/'//g" | makemv <<FIELD>> ]
| eval filter="filter2"
| eval column3 = mvindex(column2, mvfind(column1, filter))
0 Karma

HiroshiSatoh
Champion

Why use LIKE? Is not this a ”filter2%”?

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