Splunk Search

How can I display unique values of a field from a single event?

vikramphilar
New Member

Here's my input:

....
....
TradeDetailsDTO [ShortName=ABCD, allocated=600], TradeDetailsDTO [ShortName=EFGH, allocated=400], TradeDetailsDTO [ShortName=IJKL, allocated=300], TradeDetailsDTO [ShortName=MNOP, allocated=700]
....
....

Based on the text above, I am trying to get my output to be displayed in a table like below:

ShortName allocated
ABCD 600
EFGH 400
IJKL 300
MNOP 700

I tried using stats or the foreach commands but neither of them are able to pick up all the four items list in the table above. Note that this list is variable and it may not be 4 items all the time. Please advise.

Tags (2)
0 Karma

sundareshr
Legend

Try this

your base search | eval z=mvzip(ShortName, allocated, "#") | mvexpand z | rex field=z "(?<ShortName>[^#])#(?<allocated>.*)" | stats values(allocated) as allocated by ShortName
0 Karma

JDukeSplunk
Builder

Assuming your fields are extracted (ShortName and allocated) it would be something like this.

basesearch | stats values(ShortName) by allocated

or reverse

|stats values(allocated) by ShortName

Lastly a quick inline regex to extract the fields. 

 |rex field=_raw "ShortName=(?P<ShortName>\w+),allocated=(?P<allocated>\d+)" |stats values(ShortName) by allocated
0 Karma

vikramphilar
New Member

Thanks, JDukeSplunk. I tried your solution but it only prints the first row along with the column headers, i.e.:

ShortName allocated
ABCD 600

Am I missing something?

0 Karma
Get Updates on the Splunk Community!

[Puzzles] Solve, Learn, Repeat: Dynamic formatting from XML events

This challenge was first posted on Slack #puzzles channelFor a previous puzzle, I needed a set of fixed-length ...

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  &#x1f680; Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Stronger Security with Federated Search for S3, GCP SQL & Australian Threat ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...