Splunk Search

sort csv by current dates

Bentash
Explorer

I want to sort out a csv but it not working

tried
......| fields Date,count | stats by Date,count | eval Date=strptime(Date, "%d/%m/%Y") | sort Date | eval Date=strftime(Date, "%m/%Y") | chart as total over t1 by Date

I keep getting
01/2018
02/2018
03/2018

This is the result i am expecting
03/2018
02/2018
01/2018

Tags (3)
0 Karma

somesoni2
Revered Legend

The sorting that you've before chart will be ineffective as chart would do it's own sorting of output which is always in ascending order, for both rows and columns. There can be different workaround that you can try, one is prefix a sequence number in date column so that when chart sorts it, it's in the order you need.

Other workaround works if the month values that you're searching on are relative to current time OR relative to time range of the search. Is that the case?

0 Karma

FrankVl
Ultra Champion

To change the sort order, use | sort -Date to make it sort in descending order.

PS: you might want to put the sort before replacing the Date value with a string, as sorting strings may not always result in a correct sorting of dates. Or use fieldformat instead of eval, such that under the hood, it keeps the numerical timestamp value and only renders it as a string.

0 Karma

damien_chillet
Builder

Try sort - Date

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

[Puzzles] Solve, Learn, Repeat: Matching cron expressions

This puzzle (first published here) is based on matching timestamps to cron expressions.All the timestamps ...

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas     Cisco Live 2026 is almost here, and this ...

Data Management Digest – May 2026

Welcome to the May 2026 edition of Data Management Digest!   As your trusted partner in data innovation, the ...