Splunk Search

how to find difference of two field value(string) and assign it to new field

rajsplunk
Explorer

HI all

I have a scenario where i have to find the difference of two field value (string) for example

fileda="raj", "rahul", "rohan"

filedb="rahul", "rohan"

i need to have a third field as difference of the above two filed

fieldc="raj"

I am running out of ideas as how to do it. Can someone please help in this

 

Labels (1)
0 Karma
1 Solution

rajsplunk
Explorer

Hi all...I got this fix by a simple logic of set diff command..thanks everyone 

 

View solution in original post

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Please clarify the contents of these fields. Are they quoted strings separated by commas? Are they multi-value fields which each value being an unquoted string? Are they difference events with different values for the fields?

The best way to illustrate your data is to paste the raw event data into a code block (using the </> button) so that formatting from the event is preserved.

0 Karma

rajsplunk
Explorer

NO they are not quoted string seperated by comma..i think i dint put the example in the right way..let me try the below example

field_a          field_b

rohan               rohan

rahul                rahul

raj

now i need to have the difference of the above to field

field_c

raj

0 Karma

dural_yyz
Motivator

Are these values always aligned, or are the values sometimes unaligned and you still want to know if they are in both fields?

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Again, are these separate events or multi-value fields in the same event?

0 Karma

rajsplunk
Explorer

these are seperated events not a multivalue fields

0 Karma

rishabhshah
Path Finder

Let me now if below query helps -

| makeresults count=3
| streamstats count as field1
| eval field2=field1+0
| eval field2=if(field2=3, Null(), field2)
| fields - _time
| eval field3=if(field1==field2, null(), field1)

 

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| eval field_c=if(field_a == field_b, null(), field_a)
0 Karma

rajsplunk
Explorer

Hi all...I got this fix by a simple logic of set diff command..thanks everyone 

 

0 Karma
Get Updates on the Splunk Community!

See your relevant APM services, dashboards, and alerts in one place with the updated ...

As a Splunk Observability user, you have a lot of data you have to manage, prioritize, and troubleshoot on a ...

Index This | What goes away as soon as you talk about it?

May 2025 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this month’s ...

What's New in Splunk Observability Cloud and Splunk AppDynamics - May 2025

This month, we’re delivering several new innovations in Splunk Observability Cloud and Splunk AppDynamics ...