Splunk Search

Multiple eval of the same field

jlelli
Path Finder

Hi all,
I got some problems categorizing a custom field according to its content; to do so I am using multiple eval IF commands:

| eval Myfield=if(Like(Myfield, "%Windows%"), "Microsoft", Myfield) 
| eval Myfield=if(Like(Myfield, "%iPhone%"), "Apple", Myfield) 
| eval Myfield=if(Like(Myfield, "%Android%"), "Google", Myfield)

With a simple stats count by MyField i got both the number of Microsoft, Apple and Google values and the explicit values for everything else. So far is exactly what I need.

Now I want to expand this query in two ways
1- Including multiple conditions for the same value (to save writing a sigle eval for each case)

| eval Myfield=if(Like(Myfield, "%Windows%" OR "%Office%" OR "%Notepad%"), "Microsoft", Myfield)

2 - Including an "Other" value for everything that is not specified

| eval Myfield=if(NOT Like(Myfield, "%Windows%" OR "%iPhone%" OR "%Android%"), "Other", Myfield)

However neither of two is working: I got some SPL grammar or logic problem that still can't solve...

0 Karma
1 Solution

somesoni2
Revered Legend

This is the classing use case for case command. Try something like this. Also, see how the like expression for multiple matches is done here (which causing SPL issues for you before).

your base search
| eval Myfield=case(like(Myfield, "%Windows%") OR like(Myfield, "%Office%") OR like(Myfield, "%Notepad%"), "Microsoft", like(Myfield, "%iPhone%"), "Apple", like(Myfield, "%Android%"), "Google", true(),"Other")
| stats count by Myfield

View solution in original post

somesoni2
Revered Legend

This is the classing use case for case command. Try something like this. Also, see how the like expression for multiple matches is done here (which causing SPL issues for you before).

your base search
| eval Myfield=case(like(Myfield, "%Windows%") OR like(Myfield, "%Office%") OR like(Myfield, "%Notepad%"), "Microsoft", like(Myfield, "%iPhone%"), "Apple", like(Myfield, "%Android%"), "Google", true(),"Other")
| stats count by Myfield

jlelli
Path Finder

Thank You,
I still misspell some comma here and there but your logic is way simpler and faster to use.

0 Karma
Get Updates on the Splunk Community!

Index This | What is broken 80% of the time by February?

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

Unlock Faster Time-to-Value on Edge and Ingest Processor with New SPL2 Pipeline ...

Hello Splunk Community,   We're thrilled to share an exciting update that will help you manage your data more ...

Splunk MCP & Agentic AI: Machine Data Without Limits

Discover how the Splunk Model Context Protocol (MCP) Server can revolutionize the way your organization uses ...