<?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 Re: Why is eval command case function not working? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Why-is-eval-command-case-function-not-working/m-p/619043#M215148</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;Field name should be in double quotes.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Field name should not be in double quotes. &amp;nbsp;Double quote encloses literal strings in SPL. &amp;nbsp;Single quotes enclose field names.&lt;/P&gt;</description>
    <pubDate>Tue, 01 Nov 2022 04:59:10 GMT</pubDate>
    <dc:creator>yuanliu</dc:creator>
    <dc:date>2022-11-01T04:59:10Z</dc:date>
    <item>
      <title>Why is eval command case function not working?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-eval-command-case-function-not-working/m-p/619036#M215143</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I wrote a eval command and its not working. Kindly help.&lt;/P&gt;
&lt;P&gt;source = "2access_30DAY.log" | eval "new_field" = case('status'=200, 'Suman and Cloeh are best couple') | table "status" "new_field"&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="eval1.png" style="width: 999px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/22251i208496116F3D16B5/image-size/large?v=v2&amp;amp;px=999" role="button" title="eval1.png" alt="eval1.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;
&lt;P&gt;Suman P.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Nov 2022 04:19:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-eval-command-case-function-not-working/m-p/619036#M215143</guid>
      <dc:creator>SumanPalisetty</dc:creator>
      <dc:date>2022-11-01T04:19:31Z</dc:date>
    </item>
    <item>
      <title>Re: Why is eval command case function not working?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-eval-command-case-function-not-working/m-p/619038#M215145</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;source = "2access_30DAY.log"
 | eval "new_field" = case('status'==200, "Suman and Cloeh are best couple")
 | table "status" "new_field"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Nov 2022 04:21:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-eval-command-case-function-not-working/m-p/619038#M215145</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2022-11-01T04:21:15Z</dc:date>
    </item>
    <item>
      <title>Re: Why is eval command case function not working?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-eval-command-case-function-not-working/m-p/619041#M215146</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt;&amp;nbsp;but I have a question please. Field name should be in double quotes. so, shouldn't status be in double quotes? Why is it giving me an error when I use it?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="eval2.png" style="width: 857px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/22253i2976D5DD0C5BC361/image-size/large?v=v2&amp;amp;px=999" role="button" title="eval2.png" alt="eval2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Suman P.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Nov 2022 04:51:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-eval-command-case-function-not-working/m-p/619041#M215146</guid>
      <dc:creator>SumanPalisetty</dc:creator>
      <dc:date>2022-11-01T04:51:45Z</dc:date>
    </item>
    <item>
      <title>Re: Why is eval command case function not working?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-eval-command-case-function-not-working/m-p/619043#M215148</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;Field name should be in double quotes.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Field name should not be in double quotes. &amp;nbsp;Double quote encloses literal strings in SPL. &amp;nbsp;Single quotes enclose field names.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Nov 2022 04:59:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-eval-command-case-function-not-working/m-p/619043#M215148</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2022-11-01T04:59:10Z</dc:date>
    </item>
    <item>
      <title>Re: Why is eval command case function not working?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-eval-command-case-function-not-working/m-p/619044#M215149</link>
      <description>&lt;P&gt;Which means that my initial reply copied the original code too much.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;source = "2access_30DAY.log"
 | eval "new_field" = case('status'==200, "Suman and Cloeh are best couple")
 | table status new_field&lt;/LI-CODE&gt;&lt;P&gt;(When there is no ambiguity as to where the field name ends, i.e., no space or special characters in field name, you can skip single quotes.)&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Nov 2022 05:02:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-eval-command-case-function-not-working/m-p/619044#M215149</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2022-11-01T05:02:02Z</dc:date>
    </item>
    <item>
      <title>Re: Why is eval command case function not working?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-eval-command-case-function-not-working/m-p/619045#M215150</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;Field name should be in double quotes.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Field name should not be in double quotes. &amp;nbsp;Double quote encloses literal strings in SPL. &amp;nbsp;Single quotes enclose field names.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Correction. &amp;nbsp;Single quotes dereferences a field, i.e., points to a value. &amp;nbsp;When you compare with a number literal (200), you need a numerical value to compare, not a string.&lt;/P&gt;&lt;P&gt;The use of double quotes is slightly complicated. &amp;nbsp;When appearing on the left-hand side of an assignment or in tabulation (including groupby terms), they enclose field names. &amp;nbsp;In the right-hand side of an assignment or any other form of evaluation expression, they enclose literal strings.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Nov 2022 05:16:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-eval-command-case-function-not-working/m-p/619045#M215150</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2022-11-01T05:16:15Z</dc:date>
    </item>
    <item>
      <title>Re: Why is eval command case function not working?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-eval-command-case-function-not-working/m-p/619046#M215151</link>
      <description>&lt;P&gt;As &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt;&amp;nbsp;says, quoting and eval is a little complicated and can be a little confusing&lt;/P&gt;&lt;P&gt;Just remember the rule with eval&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;Left hand side&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp;(LHS) of the eval statement can ONLY use double quotes and only if needed, e.g.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval "status"=case(...)&lt;/LI-CODE&gt;&lt;P&gt;does NOT need double quotes as it does not contain spaces and can be written as&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval status=case(...)&lt;/LI-CODE&gt;&lt;P&gt;However, this left hand side MUST use double quotes, as it contains spaces&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval "Total Errors"=123&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;Right hand side&lt;/FONT&gt;&lt;/STRONG&gt;&amp;nbsp;(RHS) of the eval&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Is written without any quotes if a simple field name (e.g. just letters)&lt;UL&gt;&lt;LI&gt;e.g. status&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;SINGLE quotes if the field contains certain special characters or starts with a number&lt;UL&gt;&lt;LI&gt;e.g. 'Total Errors' or '1stValue' or 'my:Special:Field'&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;Note&lt;/FONT&gt;&lt;/STRONG&gt; though how the following seems confusing with treatment of LHS and RHS names&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval 1stValue=123
| eval value='1stValue'&lt;/LI-CODE&gt;&lt;P&gt;Although the 1stValue assignment does NOT need double quotes on the LHS even though it starts with a number, the RHS DOES need single quotes, so eval does not start to treat it as a number.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As a general rule, it is always safe to use SINGLE quotes round a field on the RHS. In your example, you put the 'Suman...' in single quotes, so Splunk thought that was a field you were assigning to new_field, hence it had no value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Nov 2022 05:38:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-eval-command-case-function-not-working/m-p/619046#M215151</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2022-11-01T05:38:54Z</dc:date>
    </item>
    <item>
      <title>Re: Why is eval command case function not working?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-eval-command-case-function-not-working/m-p/619047#M215152</link>
      <description>&lt;P&gt;In addition to this - note that the previous comment applies to EVAL and NOT to other operations such as aggregations.&lt;/P&gt;&lt;P&gt;In that case, you will use double quotes - yes I know this is confusing - but take this for example where you have fields called&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;sale price&lt;/LI&gt;&lt;LI&gt;sale quantity&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;both contain spaces and need a single quote in the EVAL, but in the stats command, the sale quantity field needs to be encapsulated in DOUBLE quotes, not single quotes.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval "dollar price"='sale quantity' * 'sale price'
| stats sum("dollar price") as "dollar total" sum("sale quantity") as quantity&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Nov 2022 05:49:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-eval-command-case-function-not-working/m-p/619047#M215152</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2022-11-01T05:49:10Z</dc:date>
    </item>
  </channel>
</rss>

