Splunk Search

merge rows to one row if matches the result value by VM ( little complex situation)

Satheesh_red
Path Finder

I have a Splunk result like below.

VMcol1col2
vm1carsedan
vm2carsedan
vm3planePriv
vm4bikeFazer
vm5bikethunder

 

I would like to make them in a below format, would you please suggest me. I want to merge the same value into one (columns merge)

Satheesh_red_1-1702569367480.png

 

 

Labels (3)
0 Karma

glc_slash_it
Path Finder

Hi,

you can group results by col1 

(search)
| stats values(VM) values(col2) by col1

 

------------
If this was helpful, some karma would be appreciated.

0 Karma

Satheesh_red
Path Finder

Hi @glc_slash_it 

Thanks for your reply,

It is giving a combination of several fields, but duplicates are showing up. I want to get rid of duplicates where two values matches and to show up as a single result value instead of two combinations.

And I want to display it by VM (in my example, VM columns will always be unique).

 

Regards,

0 Karma

bowesmana
SplunkTrust
SplunkTrust

To split by VM, just change it like this

| stats values(col*) as col* by VM

 

0 Karma

Satheesh_red
Path Finder

@bowesmana 

For more simplify it for you, split by VM and I'm looking to merge the values into one, example.

I have two values as 'car' those should be into one value and in single box. as like same if the result values matches should come. | stats values(col1) values(col2) is not helping as which is combination of values coming.

Satheesh_red_0-1702616295843.png

 

Regards, 

0 Karma

yuanliu
SplunkTrust
SplunkTrust

Splunk is not a substitute for spreadsheet application like Excel where you merge cells for visual effects.  It organizes data like a database.  As @glc_slash_it and @bowesmana explained, you either split by col1 or by VM.  You must ask yourself: Do you want to achieve Excel-like visual (split by col1) or do you want to maintain data logic (split by VM)?

If Excel-like effect is more important than data logic, the best you can emulate a cell merge as in your illustration is to use list function to retain the order of VM and col2, like

 

| stats list(*) as * by col1
| eval col2 = if(mvindex(col2, 0) == mvindex(col2, -1), mvindex(col2, 0), col2)
| table VM col*

 

Using the emulation given by @bowesmana, your mock data will give you

VM
col1
col2
vm4
vm5
bike
Fazer
thunder
vm1
vm2
carsedan
vm3planePriv

This is the closest to your mock results.  It then becomes your job to convince your users that there is an invisible split line between vm4 and vm5, vm1 and vm2, etc.

bowesmana
SplunkTrust
SplunkTrust

You can't merge a single column across 2 other columns, as in your vm4/vm4 example. You can do

| stats values(VM) as VMs by col1 col2
| sort VMs

but it will give you separate rows for vm4/vm5

0 Karma

Satheesh_red
Path Finder

@bowesmana 

Ok, Thanks for your reply. I understand. Appreciated for your reply.

VM shouldn't be in values and combine, rest of the column's should combine if result values match, and show visualize. 

I'm still looking for some alternative options here. 

 

Regards,

0 Karma

PickleRick
SplunkTrust
SplunkTrust

Also please note (it's worth mentioning because that's not obvious) that if you aggregate some values into several multivalued fields (like in your case - multivalued VM field and col2 field) the contents of those multivalued fields are from now on independent on each other. So you can't for example - sort one using the order of the other.

Again - it's not a spreadsheet.

0 Karma

bowesmana
SplunkTrust
SplunkTrust

You can't combine Splunk columns inside a Splunk table, but you can make second and subsequent duplicates clear, like this example

| makeresults format=csv data="VM,col1,col2
vm1,car,sedan
vm2,car,sedan
vm3,plane,Priv
vm4,bike,Fazer
vm5,bike,thunder"

| stats values(col*) as col* by VM
| streamstats count as c1 by col1
| streamstats count as c2 by col2
| eval col1=if(c1>1, null(), col1)
| eval col2=if(c2>1, null(), col2)
| fields - c1 c2

Satheesh_red
Path Finder

@bowesmana 

I like this logic but could be hectic to use in my current environment. thanks.

 

 

Regards,

0 Karma
Get Updates on the Splunk Community!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...