Splunk Search

How to filter the search with the following record

zhanweiw
Explorer

Hi there,

Can I know how to get the record from ver 1.1 by case sensitive excluding record from ver 1.2?

 

Currently I have data like this:

records:

============================================

index=a, ver=1.1, a="halo", b="haha", c="nana"

index=a, ver=1.1, a="testing", b="haha", c="nana"

index=a, ver=1.1, a="halo", b="kaka", c="testing"

 

index=a, ver=1.2, a="halo", b="haha", c="nana"

index=a, ver=1.2, a="lala", b="haha", c="nana"

index=a, ver=1.2, a="halo", b="kaka", c="TESTING"

============================================

 

Result expected:

index=a, ver=1.1, a="testing", b="haha", c="nana"

index=a, ver=1.1, a="halo", b="kaka", c="testing"

 

Is that possible to be done?

Labels (1)
0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

This is a run anywhere example using your data

| makeresults
| eval x="index=a, ver=1.1, a=\"halo\", b=\"haha\", c=\"nana\"##index=a, ver=1.1, a=\"testing\", b=\"haha\", c=\"nana\"##index=a, ver=1.1, a=\"halo\", b=\"kaka\", c=\"testing\"##index=a, ver=1.2, a=\"halo\", b=\"haha\", c=\"nana\"##index=a, ver=1.2, a=\"lala\", b=\"haha\", c=\"nana\"##index=a, ver=1.2, a=\"halo\", b=\"kaka\", c=\"TESTING\""
| makemv delim="##" x
| mvexpand x
| table x
| rename x as _raw
| extract
| fields - _raw
| stats values(ver) as ver by index a b c
| where ver="1.1" AND mvcount(ver)=1

The last two lines are the ones you want - and this is collapsing the versions for each of the  index/a/b/c combinations and then just checking that ver only contains 1.1

Hope this helps

View solution in original post

0 Karma

zhanweiw
Explorer

Hi bowesmana,

thank you for your answer, it works as expected.

However, I have pushed these records to Splunk database.

If I want to get the data from Splunk database and produce the same result, what query should I form?

 

0 Karma

bowesmana
SplunkTrust
SplunkTrust

The last two lines in that example were what you need to use in your query, obviously you will have to tweak the variable names according to your data if they are not as you have indicated.

 

 

0 Karma

bowesmana
SplunkTrust
SplunkTrust

This is a run anywhere example using your data

| makeresults
| eval x="index=a, ver=1.1, a=\"halo\", b=\"haha\", c=\"nana\"##index=a, ver=1.1, a=\"testing\", b=\"haha\", c=\"nana\"##index=a, ver=1.1, a=\"halo\", b=\"kaka\", c=\"testing\"##index=a, ver=1.2, a=\"halo\", b=\"haha\", c=\"nana\"##index=a, ver=1.2, a=\"lala\", b=\"haha\", c=\"nana\"##index=a, ver=1.2, a=\"halo\", b=\"kaka\", c=\"TESTING\""
| makemv delim="##" x
| mvexpand x
| table x
| rename x as _raw
| extract
| fields - _raw
| stats values(ver) as ver by index a b c
| where ver="1.1" AND mvcount(ver)=1

The last two lines are the ones you want - and this is collapsing the versions for each of the  index/a/b/c combinations and then just checking that ver only contains 1.1

Hope this helps

0 Karma

zhanweiw
Explorer

Hi Bowesmana,

I understood now.

Thank you for your help.

The last two lines are what I needed:

| stats values(ver) as ver by index a b c

| where ver="1.1" AND mvcount(ver) = 1 

0 Karma
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!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...