Security

use strings values as a variable to do stats

gsbpp
Explorer

index=myindex  ( "Sign-up experience experiment not allowed" OR "Sign-up experience experiment allowed" OR "experiments.1" )

SO, there are three string searches; the first tow differ in a "not" inside the text.

I would like to do a stats to count for the appearance of each, e.g.

| stats count by  <var>

 

Labels (1)
0 Karma
1 Solution

PrewinThomas
Motivator

@gsbpp 
You can try something below to match and do a stats count.

index=myindex (
"Sign-up experience experiment not allowed"
OR "Sign-up experience experiment allowed"
OR "experiments.1"
)
| eval phrase=case(
searchmatch("Sign-up experience experiment not allowed"), "Sign-up experience experiment not allowed",
searchmatch("Sign-up experience experiment allowed"), "Sign-up experience experiment allowed",
searchmatch("experiments.1"), "experiments.1"
)
| stats count by phrase


Regards,
Prewin
🌟If this answer helped you, please consider marking it as the solution or giving a Karma. Thanks!

View solution in original post

0 Karma

PrewinThomas
Motivator

@gsbpp 
You can try something below to match and do a stats count.

index=myindex (
"Sign-up experience experiment not allowed"
OR "Sign-up experience experiment allowed"
OR "experiments.1"
)
| eval phrase=case(
searchmatch("Sign-up experience experiment not allowed"), "Sign-up experience experiment not allowed",
searchmatch("Sign-up experience experiment allowed"), "Sign-up experience experiment allowed",
searchmatch("experiments.1"), "experiments.1"
)
| stats count by phrase


Regards,
Prewin
🌟If this answer helped you, please consider marking it as the solution or giving a Karma. Thanks!

0 Karma

gsbpp
Explorer

It worked. Thank you!

richgalloway
SplunkTrust
SplunkTrust

If the searched-for strings are in a known field then you can use that field in the stats command.

index=myindex ( "Sign-up experience experiment not allowed" OR "Sign-up experience experiment allowed" OR "experiments.1" )
| stats count by foo

OTOH, if the strings can be anywhere then it gets more involved.  We need to create a field for the stats command to use.

index=myindex ( "Sign-up experience experiment not allowed" OR "Sign-up experience experiment allowed" OR "experiments.1" )
| eval foo=case(searchmatch("Sign-up experience experiment not allowed"),"Not allowed", 
searchmatch("Sign-up experience experiment allowed"), "Allowed", searchmatch("experiments.1"), "Experiments",
1==1, "Other" )
| stats count by foo
---
If this reply helps you, Karma would be appreciated.
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Index This | What travels the world but is also stuck in place?

April 2026 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Discover New Use Cases: Unlock Greater Value from Your Existing Splunk Data

Realizing the full potential of your Splunk investment requires more than just understanding current usage; it ...

Continue Your Journey: Join Session 2 of the Data Management and Federation Bootcamp ...

As data volumes continue to grow and environments become more distributed, managing and optimizing data ...