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!

Join Us for Splunk University and Get Your Bootcamp Game On!

If you know, you know! Splunk University is the vibe this summer so register today for bootcamps galore ...

.conf24 | Learning Tracks for Security, Observability, Platform, and Developers!

.conf24 is taking place at The Venetian in Las Vegas from June 11 - 14. Continue reading to learn about the ...

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...