Splunk Search

can i use "like" in search criteria

alexl1
Path Finder

if one of my fields is host, I want to do

host like "startswith*"

what is the syntax to do that? thanks,

Tags (1)
1 Solution

JSapienza
Contributor

Here are are a couple ways.

  1. host=foo*

  2. ... | where like(host, "foo%")

View solution in original post

pranjal
Engager

whats the best way to compare with a list of items.
I am looking for something like this:
|search where NotificationEventType in ("THE_CHEESEBURGER%", "THE_HAMBURGER%", "ETC%"...)

0 Karma

th1agarajan
Path Finder

@bcherdak : What is the best way to exclude event that start with foo*?

your search | where NOT like(host,"foo%")

This should do the magic.

0 Karma

ddrillic
Ultra Champion

-- bcherdak, you asked - "What is the best way to exclude event that start with foo*?"

I would say - ... NOT host = "foo*"

0 Karma

jtacy
Builder

While it's probably safe to use NOT host="foo*" since the host field should always exist, I'd favor the host!="foo*" syntax; if you have a pattern you're matching on, you probably expect that field to exist in the results. Using the NOT approach will also return events that are missing the field which is probably not what most people want.

0 Karma

JSapienza
Contributor

Here are are a couple ways.

  1. host=foo*

  2. ... | where like(host, "foo%")

alexl1
Path Finder

thanks! ...

0 Karma

pranjal
Engager

whats the best way to compare with a list of items.
I am looking for something like this:
|search where NotificationEventType in ("THE_CHEESEBURGER%", "THE_HAMBURGER%", "ETC%"...)

0 Karma

bcherdak
New Member

What is the best way to exclude event that start with foo*?

0 Karma

jtacy
Builder

If you want to exclude events where a field doesn't start with foo*, use field!="foo*".

If you want to exclude events where the event itself doesn't start with foo*, you can use _raw!="foo*".

0 Karma
Get Updates on the Splunk Community!

Get the T-shirt to Prove You Survived Splunk University Bootcamp

As if Splunk University, in Las Vegas, in-person, with three days of bootcamps and labs weren’t enough, now ...

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Wondering How to Build Resiliency in the Cloud?

IT leaders are choosing Splunk Cloud as an ideal cloud transformation platform to drive business resilience,  ...