Splunk Search

Can I merge few rows into 1 row depending on the value of a field?

surekhasplunk
Communicator

Hi,

I have a lookup file and I am using below query to show results in statistics table in my dashboard which is working fine.

|inputlookup file1.csv |search bla bla |chart count over "Delivery Area" by "Sourcing Status" 

Am getting results as:

Delivery Area | field2 | field 3 
asdfdf-ABD-ffdfsdf | 3 |4
asdff-ABD-erewr | 5 | 6
adffs-SD-223 |4 |4
213-SD-dffh |5 |7
adf-SD-dff |7 |8

But now for the Delivery Area I need them to be merged into one row if for ex:
when I have 3 rows like below they should be merged into a new row called

All-SD | 16 | 19
adffs-SD-223
213-SD-dffh
adf-SD-dff

How do I achieve this?

Tags (3)
0 Karma

elliotproebstel
Champion

I'm assuming the following:
1. You want to join all items where Delivery Area matches on the middle section (part between two hyphens) if there exist more than one item with the same middle section.
2. If there is only one item in the list with at particular middle section, you want to identify it by name.
3. You want to sum the values of field1 and field2 for merged items and preserve the count for non-merged items.
If all of that is correct, I think this should do what you're looking for:

[ your current search]
| rex field="Delivery Area" "[^-]-(?<mergeable>[A-Z]+)-" 
| eventstats count by mergeable 
| eval title=if(count>1,"All-".mergeable, 'Delivery Area') 
| stats sum(f*) AS f* BY title
| rename title AS "Delivery Area"
0 Karma

elliotproebstel
Champion

It looks like you're merging all the rows that contain SD. Would you also be merging the first two rows into: All-ABD | 8 | 10?

0 Karma
Get Updates on the Splunk Community!

What’s new on Splunk Lantern in August

This month’s Splunk Lantern update gives you the low-down on all of the articles we’ve published over the past ...

Welcome to the Future of Data Search & Exploration

You have more data coming at you than ever before. Over the next five years, the total amount of digital data ...

This Week's Community Digest - Splunk Community Happenings [8.3.22]

Get the latest news and updates from the Splunk Community here! News From Splunk Answers ✍️ Splunk Answers is ...