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!

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...