Splunk Search

How can i use the append command based on an If condition ?

harishalipaka
Motivator

Hi All,

i have a base search ,with field A ,

If field A >0 , I have to append another search query that returns multi columns.

Thanks
Harish
0 Karma
1 Solution

FrankVl
Ultra Champion

If the base search is not overly heavy, you could include the base search in the appended subsearch, filter for A>0 in the subsearch and then only return the columns that you actually wanted to add.

So in pseudo code:

base search
| append [ base search | append [ subsearch ] | where A>0 | table subsearchfieldX subsearchfieldY ]

View solution in original post

FrankVl
Ultra Champion

If the base search is not overly heavy, you could include the base search in the appended subsearch, filter for A>0 in the subsearch and then only return the columns that you actually wanted to add.

So in pseudo code:

base search
| append [ base search | append [ subsearch ] | where A>0 | table subsearchfieldX subsearchfieldY ]

harishalipaka
Motivator

Hi @FrankVl ,
It is working. Thanks

Thanks
Harish
0 Karma

FrankVl
Ultra Champion

Note, the code was just pseudo code. If you really use append like that it will not work, as append adds it as extra lines, so you cannot filter this. It might help if you give a more concrete example of what your search looks like (without the filter).

Something like this works:

| makeresults 
| eval A=1
| table A
| appendcols [ | makeresults | eval A=1 | appendcols [ | makeresults | eval b=1,c=2,d=3 ] | where A>0 | table b,c,d ]

This returns all 4 fields. When running the same example but with A=0, it only returns A:

| makeresults 
| eval A=0
| table A
| appendcols [ | makeresults | eval A=0 | appendcols [ | makeresults | eval b=1,c=2,d=3 ] | where A>0 | table b,c,d ]
0 Karma

inventsekar
SplunkTrust
SplunkTrust

@FrankVl Superb one!
i learnt this append tidbit from you.
(learning and using this append, appendcols are difficult areas, even for many experienced splunk admins)

thanks and best regards,
Sekar

PS - If this or any post helped you in any way, pls consider upvoting, thanks for reading !
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 ...