Archive
Highlighted

How to combine two fields if the second field does not equal 0?

Communicator

Okay I have two fields, first one is an error code, example:
ErrorCode_Field = 404

The second field is a sub code of that error code, example:
SubErrorCode_Field = 3

For some reason they entire code is split into two separate fields. I was able to combine the two into a single field to look like this:
FullErrorCode_Field=404.3

Using this code:
eval "FullErrorCodeField"=ErrorCodeField . "." . SubErrorCode_Field |

But I would like to put in some kind of "if" statement that says if the SubErrorCodeField = 0 to not append it or the "." between the split fields to the FullErrorCodeField. So for example:

if ErrorCodeField = 404 and SubErrorCodeField = 3 then FullErrorCode_Field=404.3 but

if ErrorCodeField = 404 and SubErrorCodeField = 0 then FullErrorCode_Field=404

0 Karma
Highlighted

Re: How to combine two fields if the second field does not equal 0?

SplunkTrust
SplunkTrust

Try like this
fixed typo

your current search | eval "FullErrorCode_Field"=ErrorCode_Field.if(tonumber(SubErrorCode_Field)=0,"",".".SubErrorCode_Field)

View solution in original post

0 Karma
Highlighted

Re: How to combine two fields if the second field does not equal 0?

Communicator

You the man, that did the trick!

Highlighted

Re: How to combine two fields if the second field does not equal 0?

SplunkTrust
SplunkTrust

Thanks @snix for pointing the typo. Corrected the answer.

0 Karma