Splunk Search

How to unite multiple columns into one column?

krim
Explorer

table A

krim_0-1664425523884.png

table B

krim_1-1664425551716.png

 I know there are lots of ways to spread the table from table B to table A . Is there ant method to transform table A to table B in Splunk without losing any data? like unite in R, pivot in BQ?

 

Labels (3)
0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

The untable command does that - see this example

| makeresults
| eval _raw="ID,A,B,C
1122,1,2,5
1144,2,3,5
1155,1,9,4"
| multikv forceheader=1 
``` This is your table A ```
| table ID, A, B, C
``` Now convert to your table B ```
| untable ID pick number

View solution in original post

bowesmana
SplunkTrust
SplunkTrust

The untable command does that - see this example

| makeresults
| eval _raw="ID,A,B,C
1122,1,2,5
1144,2,3,5
1155,1,9,4"
| multikv forceheader=1 
``` This is your table A ```
| table ID, A, B, C
``` Now convert to your table B ```
| untable ID pick number

krim
Explorer

Hi, I try to apply untable on a table like this
|untable id class pick num

krim_0-1664435047043.png

I try to get a table like this ,but it doesn't work.

krim_1-1664435088795.png

Is there any way to solve this one?

0 Karma

bowesmana
SplunkTrust
SplunkTrust

To use untable to add an extra dimension, you would need to combine the fields forming the left hand item, like this

| makeresults
| eval _raw="ID,Class,A,B,C
1122,C1,1,2,5
1144,C2,2,3,5
1155,C3,1,9,4"
| multikv forceheader=1 
``` This is your table A ```
| eval ID=ID.":".Class
| table ID A B C

``` Now convert to your table B ```
| untable ID pick number
| rex field=ID "(?<ID>[^:]*):(?<Class>.*)"
| table ID Class pick number

which is creating the ID fields as ID+":"+Class and then untabling and then splitting back out the Class after the untable.

There would be other ways to do the same thing in Splunk - there is always more than one way... Here is another way to do it with the additional class field

| makeresults
| eval _raw="ID,Class,A,B,C
1122,C1,1,2,5
1144,C2,2,3,5
1155,C3,1,9,4"
| multikv forceheader=1 
``` This is your table A ```
| table ID Class A B C
``` Now combine all the row values to a single field 'Values' and remove the original fields ```
| eval Values=mvappend(A, B, C)
| fields - A B C
``` and now expand those values ```
| mvexpand Values

krim
Explorer

that works thx!!!!

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Agent Mode Engaged! Enchaining Agentic Operations with Splunk AI Assistant 2.0

    Are you ready to transform how your team handles complex data requests? We invite you to our upcoming ...

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...