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!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...