Splunk Search

How do you sort columns within a column?

psangli
Explorer

For example

Name Code Pool
Name1 100 p1
57 p32
63 p43
230 p27

Name2 120 p2
77 p33
83 p44
250 p28

should become

Name Code Pool
Name1 230 p27
100 p1
63 p43
57 p32

Name2 250 p28
120 p2
83 p44
77 p33

Tags (2)
0 Karma

DalJeanis
SplunkTrust
SplunkTrust

If you mark your data as code, then the interface will not slam it all to the left like that.

0 Karma

woodcock
Esteemed Legend

Like this:

|makeresults | eval raw="Name1 100 p1
Name1 57 p32
Name1 63 p43
Name1 230 p27
Name2 120 p2
Name2 77 p33
Name2 83 p44
Name2 250 p28"
| makemv delim="
" raw
| mvexpand raw
| rename raw AS _raw
| rex "^(?<Name>\S+)\s+(?<Code>\S+)\s+(?<Pool>\S+)$"
| stats count BY Name Code Pool
| stats list(*) AS * BY Name

| rename COMMENT AS "Everything above generates sample event data; everything below is your solution"

| eval Combo=mvzip(Code, Pool)
| fields Name Combo
| mvexpand Combo
| rex field=Combo "^(?<Code>[^,]+),(?<Pool>.*)$"
| sort 0 - Code
| fields - Combo
| stats list(*) AS * BY Name

somesoni2
SplunkTrust
SplunkTrust

It would've been better if you had posted your current search generating those output. Assuming that your last command was something on the lines of ..| stats list(Code) as Code list(Pool) as Pool by Name OR ..| stats values(Code) as Code values(Pool) as Pool by Name, give this a try..

your current search before the last stats
| sort 0 Name -Code 
| stats list(Code) as Code list(Pool) as Pool by Name
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...