Splunk Search

if-else condition

abhayneilam
Contributor

Can I use like this :

| eval a=if(Location!=" ",stat count by Location)

but I am getting error..

actually I want to find..I want to get the count for those records which are non-blank

Please help

Tags (2)
0 Karma

yannK
Splunk Employee
Splunk Employee

I am not sure that you can use conditional searches, just conditional field calculation using eval.

another way is to make sure that the field location exits, then count
| WHERE NOT ( Location=" " OR isnull(Location) ) | stat count by Location

0 Karma

Ayn
Legend

You could also include it in the stats command directly:

stats count(eval(Location==" " OR isnull(Location))
0 Karma
Get Updates on the Splunk Community!

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...