Splunk Search

Is it possible to use | format to get !=?

fredclown
Builder

I have a search and in the initial part of the search I have a subquery that returns some IP addresses formatted like this using the | format command.

 

(ip="10.10.10.10 OR ip="1.1.1.1" OR ip="2.2.2.2")

 

I have a different search where I want to negate it. Is there a way to do this? I know that the format command does allow you to do things like this ...

 

(NOT ip="10.10.10.10 NOT ip="1.1.1.1" NOT ip="2.2.2.2")

 

However, NOT ip="value" is not the same as ip!="value" in Splunk land. So, I guess I'm wondering if anyone has a great way in a subquery to pass back the field/value pairs with != rather than =. My hunch is | format can't do it, but maybe there is a different way. Hope that makes sense.

Labels (1)
0 Karma
1 Solution

PickleRick
SplunkTrust
SplunkTrust

Remember that if your subsearch returns a field called "search", it's returned verbatim to the outer search. So you can craft a search string yourself if the format command isn't sufficient.

Run-anywhere example:

| makeresults count=20
| streamstats count
| search
[| makeresults count=10
| streamstats count
| table count
| eval count="count!=".count
| stats values(count) as search
| eval search=mvjoin(search," AND ")]

View solution in original post

PickleRick
SplunkTrust
SplunkTrust

Remember that if your subsearch returns a field called "search", it's returned verbatim to the outer search. So you can craft a search string yourself if the format command isn't sufficient.

Run-anywhere example:

| makeresults count=20
| streamstats count
| search
[| makeresults count=10
| streamstats count
| table count
| eval count="count!=".count
| stats values(count) as search
| eval search=mvjoin(search," AND ")]

fredclown
Builder

That is a good option. I think my way would  work as well, but I like the output of something like this better. It looks cleaner.

0 Karma

fredclown
Builder

After thinking about it more for a bit I think this should work and do the same thing as != for each field/value pair but still allows me to use | format.

| format "ip=* AND (NOT" "" "" "" "NOT" ")"

I think this should give me the same results. Does this look right? 

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!

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 ...