Splunk Search

Easy way to match just the beginning of a field value

jravida
Communicator

Hi Folks,

I'm having a hard time working around using a wildcard within an eval, which isn't possible as far as I know.

Say I have these field values:
Bought an orange
Bought a banana
Bought a cantelope
Sold a monkey
Sold an elephant
Bought a lion

I want to count, simply, how many times "Bought" show up, and how many times "Sold" show up, so I can chart them.

Eval statements prevent wildcards, so I can't think of what to use. Is there a simple method of doing this?

Tags (3)
0 Karma
1 Solution

somesoni2
Revered Legend

Eval does except wildcard ('%') for the function 'like'. Try below expression

your base search | stats count(eval(like(yourfield,"Bought %"))) BoughtCount count(eval(like(yourfield,"Sold %"))) SoldCount

View solution in original post

the_wolverine
Champion
Bought OR Sold | rex "(?<transaction>Bought|Sold[^ ]+)" | timechart span=1h count by transaction
0 Karma

somesoni2
Revered Legend

Eval does except wildcard ('%') for the function 'like'. Try below expression

your base search | stats count(eval(like(yourfield,"Bought %"))) BoughtCount count(eval(like(yourfield,"Sold %"))) SoldCount
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...