Splunk Search

How do I compare fields between two events?

hacktastic
Path Finder

Hi,

I'm Splunking some report data that is in CSV format, which may or may not matter in the context of this question. I've got Splunk set up to index the CSV data line-by-line and I've set props.conf and transforms.conf to properly assign fields to the CSV data, so that's all done. I need to do a comparison of the dates between two events that are coming from two different hosts but share common fields. For example:

Log1 from HostA: "field1","field2","field3","dateA"

Log2 from HostB: "field1","field2","field3","dateB"

In plain English: "Match up the lines from HostA and HostB where field1, field2 and field3 are identical, then compare the dates. If the dates do not match, report this back."

I'm drawing a blank on how to do this. Your help is appreciated!

Tags (2)
1 Solution

gkanapathy
Splunk Employee
Splunk Employee

Not entirely sure I understand, but how about:

... | stats distinct_count(datefield) as diff_dates by field1,field2,field3 | where diff_dates > 1

View solution in original post

Lowell
Super Champion

Here are two approaches, not sure which will work best for you:

Search 1:

your search | transaction fields="field1,field2,field3" | search duration>0

Search 2:

your search | stats dc(_time) as times, values(_time) as time_values, by field1, field2, field3 | search times>1 | convert ctime(time_values)

It's not clear from your question if dateA and dateB represent two different dates or two different field names. In the searches above, I'm assuming that your actually talking about the timestamp of your event, which is accessible in the _time field.

If you do have two field names, then perhaps this could work for you:

your search | transaction fields="field1,field2,field3" | where dateA!=dateB

Note: You have to use where when you are comparing the value of two different fields. You can use search if you are comparing against a constant value.

0 Karma

hacktastic
Path Finder

DateA and DateB are part of the results, not time stamps. I need to know if these dates differ.

0 Karma

gkanapathy
Splunk Employee
Splunk Employee

Not entirely sure I understand, but how about:

... | stats distinct_count(datefield) as diff_dates by field1,field2,field3 | where diff_dates > 1

hacktastic
Path Finder

Awesome. Thanks again!

0 Karma

gkanapathy
Splunk Employee
Splunk Employee

... | stats max(datefield) as d1, min(datefield) as d2 by field1,field2,field3 | eval ddiff = d1-d2 | where ddiff <> 0

0 Karma

hacktastic
Path Finder

That does it, but I'd like to know the difference in time between the two dates as well in, say, hours.

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!

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

What Is the Name of the USB Key Inserted by Bob Smith? (BOTS Hint, Not the Answer)

Hello Splunkers,   So you searched, “what is the name of the usb key inserted by bob smith?”  Not gonna lie… ...

Automating Threat Operations and Threat Hunting with Recorded Future

    Automating Threat Operations and Threat Hunting with Recorded Future June 29, 2026 | Register   Is your ...