<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to use the where command in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-where-command/m-p/361857#M106895</link>
    <description>&lt;P&gt;source="&lt;EM&gt;mhn-splunk.log&lt;/EM&gt;" | where dest like "88ea2fb8-b579-11e7-8239-ce584c37994e" replace 127.0.0.1 WITH 37.139.29.33 IN dest | where dest like "fb60d976-b578-11e7-8239-ce584c37994e" replace 127.0.0.1 WITH 139.59.57.136 IN dest | where dest like "574e6d3e-b579-11e7-8239-ce584c37994e" replace 127.0.0.1 WITH 159.203.116.197 IN dest | top dest | fields dest, count&lt;/P&gt;

&lt;P&gt;why doesn't this work?&lt;/P&gt;</description>
    <pubDate>Tue, 14 Nov 2017 17:28:14 GMT</pubDate>
    <dc:creator>nielsfranken198</dc:creator>
    <dc:date>2017-11-14T17:28:14Z</dc:date>
    <item>
      <title>How to use the where command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-where-command/m-p/361857#M106895</link>
      <description>&lt;P&gt;source="&lt;EM&gt;mhn-splunk.log&lt;/EM&gt;" | where dest like "88ea2fb8-b579-11e7-8239-ce584c37994e" replace 127.0.0.1 WITH 37.139.29.33 IN dest | where dest like "fb60d976-b578-11e7-8239-ce584c37994e" replace 127.0.0.1 WITH 139.59.57.136 IN dest | where dest like "574e6d3e-b579-11e7-8239-ce584c37994e" replace 127.0.0.1 WITH 159.203.116.197 IN dest | top dest | fields dest, count&lt;/P&gt;

&lt;P&gt;why doesn't this work?&lt;/P&gt;</description>
      <pubDate>Tue, 14 Nov 2017 17:28:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-where-command/m-p/361857#M106895</guid>
      <dc:creator>nielsfranken198</dc:creator>
      <dc:date>2017-11-14T17:28:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the where command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-where-command/m-p/361858#M106896</link>
      <description>&lt;P&gt;The &lt;CODE&gt;where&lt;/CODE&gt; command accepts a single eval expression.  Your query uses two expressions - &lt;CODE&gt;like&lt;/CODE&gt; and &lt;CODE&gt;replace&lt;/CODE&gt;.  What's more, your query uses the &lt;CODE&gt;replace&lt;/CODE&gt; command rather than the &lt;CODE&gt;eval&lt;/CODE&gt; function of the same name (yes, it can be confusing to have two similar behaviors with the same name).  &lt;/P&gt;

&lt;P&gt;Your query can be replaced with either&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | where dest like "88ea2fb8-b579-11e7-8239-ce584c37994e" | replace 127.0.0.1 WITH 37.139.29.33 IN dest| ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;or&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... |where dest like "88ea2fb8-b579-11e7-8239-ce584c37994e" | eval dest=replace(dest, "127\.0\.0\.1", "37\.139\.29\.33") |...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Be aware the &lt;CODE&gt;where&lt;/CODE&gt; command discards events that don't match so it doesn't make sense to have multiple &lt;CODE&gt;where dest like&lt;/CODE&gt; commands since only dest values that match the first expression will be passed to subsequent commands.&lt;/P&gt;

&lt;P&gt;Also, it doesn't make sense to compare the dest field to a GUID and then compare it to an IP address.  In a single event, the field will contain one or the other.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Nov 2017 18:57:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-where-command/m-p/361858#M106896</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2017-11-14T18:57:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the where command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-where-command/m-p/361859#M106897</link>
      <description>&lt;P&gt;so if i am understanding correctly i can't do multiple where, replace's and eval's in one query?&lt;/P&gt;</description>
      <pubDate>Tue, 14 Nov 2017 19:38:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-where-command/m-p/361859#M106897</guid>
      <dc:creator>nielsfranken198</dc:creator>
      <dc:date>2017-11-14T19:38:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the where command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-where-command/m-p/361860#M106898</link>
      <description>&lt;P&gt;can a where never be used with replace or eval in same nested query&lt;/P&gt;</description>
      <pubDate>Tue, 14 Nov 2017 19:39:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-where-command/m-p/361860#M106898</guid>
      <dc:creator>nielsfranken198</dc:creator>
      <dc:date>2017-11-14T19:39:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the where command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-where-command/m-p/361861#M106899</link>
      <description>&lt;P&gt;@nielsfranken1989, seems like you are looking for &lt;CODE&gt;case()&lt;/CODE&gt; eval function, which allows you to evaluate multiple conditions and set the values according to the same. While you have used &lt;CODE&gt;replace&lt;/CODE&gt; command the same can be used as evaluation function as well. Refer to the documentation:&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/ConditionalFunctions#case.28X.2C.22Y.22.2C....29"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/ConditionalFunctions#case.28X.2C.22Y.22.2C....29&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/TextFunctions#replace.28X.2CY.2CZ.29"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/TextFunctions#replace.28X.2CY.2CZ.29&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Following is a run anywhere search with some mock &lt;CODE&gt;dest&lt;/CODE&gt; values. Commands till &lt;CODE&gt;mvexpand&lt;/CODE&gt; just generate mock data. You would need to place your own base search to get dest field.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval dest="88ea2fb8-b579-11e7-8239-ce584c37994e 127.0.0.1;fb60d976-b578-11e7-8239-ce584c37994e 127.0.0.1;574e6d3e-b579-11e7-8239-ce584c37994e 127.0.0.1;11aa2bb3-c456-78d9-1011-ef121g31415h 127.0.0.1;"
| makemv dest delim=";"
| mvexpand dest
| top dest  showperc=f
| eval dest=case(match(dest,"88ea2fb8-b579-11e7-8239-ce584c37994e"), replace(dest,"127.0.0.1","37.139.29.33"),
                 match(dest,"fb60d976-b578-11e7-8239-ce584c37994e"), replace (dest,"127.0.0.1","139.59.57.136"),
                 match(dest,"574e6d3e-b579-11e7-8239-ce584c37994e"), replace(dest,"127.0.0.1","159.203.116.197"),
                 true(),dest) 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS: &lt;BR /&gt;
As you would notice, I have performed &lt;CODE&gt;top&lt;/CODE&gt; command before &lt;CODE&gt;replace&lt;/CODE&gt;. Transforming command should always be placed before streaming command if possible. In simple words, lets say you have 100 events and the top command reduces the same to 10 unique destinations (dest), then eval will be performed only on 10 rows instead of 100. So you can image how much performance improvement will be there if you have thousands or millions of events.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;Top&lt;/CODE&gt; command has a parameter called &lt;CODE&gt;showperc&lt;/CODE&gt; which can be set to either &lt;CODE&gt;f&lt;/CODE&gt; or &lt;CODE&gt;false&lt;/CODE&gt; to hide percent column. Hence you would not need a separate &lt;CODE&gt;fields&lt;/CODE&gt; pipe in the end. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Nov 2017 21:22:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-where-command/m-p/361861#M106899</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-11-14T21:22:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the where command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-where-command/m-p/361862#M106900</link>
      <description>&lt;P&gt;Yes, you can use multiple &lt;CODE&gt;replace&lt;/CODE&gt; and &lt;CODE&gt;eval&lt;/CODE&gt; commands in the same query.  You can also use multiple &lt;CODE&gt;where&lt;/CODE&gt; commands, with care.  Think of each &lt;CODE&gt;where&lt;/CODE&gt; command as being ANDed with the others.  It doesn't make sense to say "where dest=foo | where dest=bar" since a field can only have one value.  You can, of course, say "where dest=foo | where src=baz".&lt;/P&gt;

&lt;P&gt;@niketnilay has a good suggestion to use &lt;CODE&gt;case&lt;/CODE&gt; to combine your conditions.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2017 12:56:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-where-command/m-p/361862#M106900</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2017-11-15T12:56:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to use the where command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-where-command/m-p/361863#M106901</link>
      <description>&lt;P&gt;There are no restrictions on using &lt;CODE&gt;where&lt;/CODE&gt;, &lt;CODE&gt;replace&lt;/CODE&gt;, and &lt;CODE&gt;eval&lt;/CODE&gt; in the same query.&lt;BR /&gt;
The "where foo replace x with y in z" construct is not valid SPL, however.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Nov 2017 15:27:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-the-where-command/m-p/361863#M106901</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2017-11-15T15:27:51Z</dc:date>
    </item>
  </channel>
</rss>

