Splunk Search

Using the foreach command, how do you reset the value of a field based on another field?

sahil237888
Path Finder

How do you reset a value of a field (to 0) based on another field's 0 value (using foreach - as this needs to be done for multiple columns)?

Tags (1)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

The general form is | foreach foo* [ eval <<FIELD>>=if(otherField=0, 0, <<FIELD>>) ].

---
If this reply helps you, Karma would be appreciated.
0 Karma

niketn
Legend

@sahil237888 if you can post some example of current results you have and expected output after foreach, it would be easier for community to assist you better. Kindly mock/anonymize any sensitive information before posting.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

sahil237888
Path Finder

_time A B C TA TB TC
0:01 1 0 1 0 1 0
0:02 1 0 5 0 2 0
0:03 0 0 0 1 3 1
0:04 5 5 0 0 0 1
0:05 0 4 0 1 0 1
0:06 0 9 4 2 0 0
0:07 0 1 5 3 0 0
0:08 0 3 7 4 0 0
0:09 0 8 1 5 0 0
0:10 6 0 3 6 1 0

As in above in column A the value in 0:10 is 6, So the corresponding value of TA for the same time should become 0 (but it becomes 6)

0 Karma

sahil237888
Path Finder

Can anyone or Splunk team help onto this?

0 Karma

renjith_nair
Legend

@sahil237888,
On what basis, value of TA should be 0 ? Just because A is 6 and you want to substract that value? At 0:10 value of B is 3 , what shoud be the value of TB?

---
What goes around comes around. If it helps, hit it with Karma 🙂
0 Karma

sahil237888
Path Finder

The value in TA ,TB, or TC represent the counter which keeps on increasing if there is corresponding zero in A,B or C.
As in A column at 00.10 value is 6 so TA should be 0.Same case is with others B and C column.
(I have multiple number of column for ehich i will implement the logic)

0 Karma

sahil237888
Path Finder

Can anyone help on this?

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...