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!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...