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
Legend

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
Revered Legend

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
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!

Deep Dive: Accelerate threat investigation with Splunk’s AI Assistant in Security

AI is one of the biggest topics in the market today, and for security teams, its value goes far beyond the ...

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 ...

Detection Engineering Office Hours: Real-World Troubleshooting & Q&A

[REGISTER HERE] This thread is for the Community Office Hours session on Detection Engineering Office Hours: ...