Splunk Search

Sort issue

jugarugabi
Path Finder

Hey all, 

I am having a file that has the following stuff:

#9
#10
#4
#1
..
#6

For everything that is not #9 or #10, I already made a replacement and it shows #other for #4/#6, etc. 
But when the statistics are shown, I am seeing the following order: 

#10
#9
#other

I want to have the following output: 
#9
#10
#other. 

The search string i am using here is not providing the desired output: 

index = app_events_dbdetect_actimize_event_us_uat sourcetype = txndata Return_code_sent_to_SIL="#*"
| eval Return_code_sent_to_SIL=if(Return_code_sent_to_SIL="#9" OR Return_code_sent_to_SIL="#10", Return_code_sent_to_SIL, "#other")
| top limit=0 Return_code_sent_to_SIL
| inputlookup append=true lookup_0_error_totals.csv
| stats max(count) as "Total errors" by Return_code_sent_to_SIL
| rename Return_code_sent_to_SIL as "#error"
| eval sort_Return_code_sent_to_SIL=case("#error"="#9",1, "#error"="#10",2, "#error"="#other",4) | sort by sort_Return_code_sent_to_SIL

What am I doing wrong? 

Thanks!

Labels (2)
0 Karma
1 Solution

scelikok
SplunkTrust
SplunkTrust

Hi @jugarugabi,

Please try below;

index = app_events_dbdetect_actimize_event_us_uat sourcetype = txndata Return_code_sent_to_SIL="#*"
| eval Return_code_sent_to_SIL=if(Return_code_sent_to_SIL="#9" OR Return_code_sent_to_SIL="#10", Return_code_sent_to_SIL, "#other")
| top limit=0 Return_code_sent_to_SIL
| inputlookup append=true lookup_0_error_totals.csv
| stats max(count) as "Total errors" by Return_code_sent_to_SIL
| eval Return_code_sent_to_SIL=replace(Return_code_sent_to_SIL,"#","")
| sort Return_code_sent_to_SIL
| eval Return_code_sent_to_SIL="#".Return_code_sent_to_SIL
If this reply helps you an upvote and "Accept as Solution" is appreciated.

View solution in original post

jugarugabi
Path Finder

So I needed to remove the # there for the sorting to work out. 

Thanks!

0 Karma

scelikok
SplunkTrust
SplunkTrust

Hi @jugarugabi,

Please try below;

index = app_events_dbdetect_actimize_event_us_uat sourcetype = txndata Return_code_sent_to_SIL="#*"
| eval Return_code_sent_to_SIL=if(Return_code_sent_to_SIL="#9" OR Return_code_sent_to_SIL="#10", Return_code_sent_to_SIL, "#other")
| top limit=0 Return_code_sent_to_SIL
| inputlookup append=true lookup_0_error_totals.csv
| stats max(count) as "Total errors" by Return_code_sent_to_SIL
| eval Return_code_sent_to_SIL=replace(Return_code_sent_to_SIL,"#","")
| sort Return_code_sent_to_SIL
| eval Return_code_sent_to_SIL="#".Return_code_sent_to_SIL
If this reply helps you an upvote and "Accept as Solution" is appreciated.
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

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