Splunk Search

How to convert a crosstable into a list format to use as a lookup file?

HeinzWaescher
Motivator

Hi,

I would like to convert a crosstable into a list.

Date      | A | B 
01.01.2014| 5 | 2
02.01.2014| 5 | 2
03.01.2014| 8 | 9

The output should be:

col1       |col2| col3
01.01.2014 | A | 5
01.01.2014 | B | 2
02.01.2014 | A | 5
02.01.2014 | B | 2
03.01.2014 | A | 8
03.01.2014 | B | 9

Is there an easy way to do this? I tried out the transpose command, but without success.

BR

Heinz

Tags (4)
0 Karma
1 Solution

tom_frotscher
Builder

I think this might not be the best solution. But maybe this is a good starting point:

| inputlookup answers.csv | stats values(A) as col3 by Date | eval col2="A" | append [| inputlookup answers.csv | stats values(B) as col3 by Date | eval col2="B"] | rename Date as col1 | sort col1 | table col*

View solution in original post

somesoni2
SplunkTrust
SplunkTrust

This should work

| inputlookup lookup.csv | untable Date col2 col3
0 Karma

HeinzWaescher
Motivator

unfortunately this command only accepts 3 arguments, but I will need more soon.

0 Karma

tom_frotscher
Builder

I think this might not be the best solution. But maybe this is a good starting point:

| inputlookup answers.csv | stats values(A) as col3 by Date | eval col2="A" | append [| inputlookup answers.csv | stats values(B) as col3 by Date | eval col2="B"] | rename Date as col1 | sort col1 | table col*

HeinzWaescher
Motivator

Thanks, this works! But I think it could be easier to prepare the flat list with excel & pivot before importing, when there will be more columns. This search needs an update every time a new column is added.

0 Karma

HeinzWaescher
Motivator

The "search" for the conversion would be

| inputlookup lookup.csv | ...

0 Karma

HeinzWaescher
Motivator

Hi Patrick,

there is no search 🙂 My goal is just convert an uploaded csv, which looks like the above example (a crosstable). I want to use it as a lookup file, therefore I need to flatten it. I can do it everytime with excel before uploading, but a Splunk solution would be much more comfortable.

0 Karma

ppablo
Retired

Hi @HeinzWaescher

It'll be helpful if you can paste your current search query that people can work with and tweak to get the result you want 🙂

Patrick

0 Karma
Get Updates on the Splunk Community!

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

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...