Splunk Search

I have duplicate entries in a CSV file. How to write a search that extracts the FIRST entry?

dbcase
Motivator

Hi,

I have a CSV file that looks like this

Date,Version
01-24-2017 12:09:26,7_3_10_000500_3851898
01-25-2017 12:09:26,7_3_10_000500_3851898
01-26-2017 12:09:26,7_3_10_000500_3851898
01-27-2017 12:09:26,7_3_10_000500_3851899
01-28-2017 12:09:26,7_3_10_000500_3851899
01-29-2017 12:09:26,7_3_10_000500_3851899
01-30-2017 12:09:26,7_3_10_000500_3851899

How can I write a search that extracts the FIRST entry so the final results would look like this

 Date,Version
 01-24-2017 12:09:26,7_3_10_000500_3851898
 01-27-2017 12:09:26,7_3_10_000500_3851899

Thank you!!!

0 Karma
1 Solution

dbcase
Motivator

Found it.....

dedup Version sortby +_time

View solution in original post

0 Karma

gokadroid
Motivator

How about using the last which returns the last seen (oldest) version as search is in reverse chronological order, something like this:

| inputlookup your csv name
| stats last(Date) by Version
| sort Version

Alternatively you can use first to reverse the affect:

| inputlookup your csv name
| stats first(Date) by Version
| sort Version
0 Karma

dbcase
Motivator

Found it.....

dedup Version sortby +_time
0 Karma

dbcase
Motivator

Final query looks like this

(index=allmsos  source=*Beta.csv*) |dedup Version sortby +_time|where Date!="Date" and Version!="Version"|eval newdatefield=strftime(strptime(Date, "%m-%d-%Y %H:%M:%S"), "%m-%d-%Y %a")|stats values(newdatefield) as Date values(Version) as Version
0 Karma

DalJeanis
Legend

Well done. Please mark your answer accepted.

0 Karma

dbcase
Motivator

Note the version number change betweeen the 24th and the 27th

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...