Splunk Search

creating an 'other' field with eval

tomlongfield
Engager

I am quite knew to this and not remotely wedded to eval as the solution for this problem, I am eager to know if there is a better way to do this.

I am currently using this query:

index=cpdata | eval ua = case(
    match(userAgent, "MSIE"), "Windows",
    match(userAgent, "Windows"), "Windows",
    match(userAgent, "Android"), "Android",
    match(userAgent, "BlackBerry"), "BlackBerry",
    match(userAgent, "like Mac OS X"), "iOS"
) | chart count by ua | sort by count | reverse

Which is successfully giving me what I expect to see.. I want to create a further case of 'Other' where anything that doesn't match is counted though. I have not managed to do this.

Tags (2)
0 Karma
1 Solution

Richfez
SplunkTrust
SplunkTrust

Try this - one always equals one so it'll always be true...

 index=cpdata | eval ua = case(
     match(userAgent, "MSIE"), "Windows",
     match(userAgent, "Windows"), "Windows",
     match(userAgent, "Android"), "Android",
     match(userAgent, "BlackBerry"), "BlackBerry",
     match(userAgent, "like Mac OS X"), "iOS",
     1==1, "Other"
 ) | chart count by ua | sort by count | reverse

View solution in original post

Richfez
SplunkTrust
SplunkTrust

Try this - one always equals one so it'll always be true...

 index=cpdata | eval ua = case(
     match(userAgent, "MSIE"), "Windows",
     match(userAgent, "Windows"), "Windows",
     match(userAgent, "Android"), "Android",
     match(userAgent, "BlackBerry"), "BlackBerry",
     match(userAgent, "like Mac OS X"), "iOS",
     1==1, "Other"
 ) | chart count by ua | sort by count | reverse

tomlongfield
Engager

Works perfectly, thank you.

0 Karma
Get Updates on the Splunk Community!

Celebrating Fast Lane: 2025 Authorized Learning Partner of the Year

At .conf25, Splunk proudly recognized Fast Lane as the 2025 Authorized Learning Partner of the Year. This ...

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...