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!

Splunk Observability Cloud's AI Assistant in Action Series: Auditing Compliance and ...

This is the third post in the Splunk Observability Cloud’s AI Assistant in Action series that digs into how to ...

Splunk Community Badges!

  Hey everyone! Ready to earn some serious bragging rights in the community? Along with our existing badges ...

What You Read The Most: Splunk Lantern’s Most Popular Articles!

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