Splunk Search

How to edit my search to select the newest event based on LastModTime field?

joesrepsol
Path Finder

So I'm taking in data from a source that has some duplicate records for the same ID. The only differentiator between events is a "LastModTime" field value, which is an integer. larger number means most recent change.

So I'm trying to write a Splunk search to get all the events from this data source, and where multiple ID exists, only give me the most recent event (i.e. LastModTime is the largest value). Sounded so easy to say, but proving to be a challenge with mvindex command and now I'm stumped.

ID LastModTime Counter
108 1495147243 1
109 1495152331 1
110 1495207972 1
111 1495205705 1
112 1495207542 1
113 1495209093 1 I only want this event out of all the ID=113 events
113 1495217660 1
113 1495218310 1
113 1495222596 1

114 1495211855 1
115 1495212746 1

help?

0 Karma

somesoni2
Revered Legend

Assuming that your _time value is setup based on LastModTime field and you get one ID in one event/row, try this

your base search | dedup ID

It should keep only the latest record for every ID if it appears more that once.

If your _time field is not based on LastModTime field, try this

yourbase search | sort 0 ID -LastModTime | dedup ID

joesrepsol
Path Finder

That worked perfect! Thank you!

yourbase search | sort 0 ID -LastModTime | dedup ID

0 Karma
Get Updates on the Splunk Community!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

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