<?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 Reassign (or keep) variable in eval's IF statement in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Reassign-or-keep-variable-in-eval-s-IF-statement/m-p/50623#M12175</link>
    <description>&lt;P&gt;I have two variables and based on one would like to possible change the value of the other:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;.. | eval a="foo" | eval b="some value" | eval a=if(match(b, "kittens"), "bar", a)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So if b contains 'kittens' make a's value equal 'bar', otherwise keep it 'foo'.  Is this possible?  As it stands now a only ever has a value when b contains 'kittens'.&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
Kevin&lt;/P&gt;</description>
    <pubDate>Fri, 29 Jul 2011 17:03:43 GMT</pubDate>
    <dc:creator>kevintelford</dc:creator>
    <dc:date>2011-07-29T17:03:43Z</dc:date>
    <item>
      <title>Reassign (or keep) variable in eval's IF statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Reassign-or-keep-variable-in-eval-s-IF-statement/m-p/50623#M12175</link>
      <description>&lt;P&gt;I have two variables and based on one would like to possible change the value of the other:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;.. | eval a="foo" | eval b="some value" | eval a=if(match(b, "kittens"), "bar", a)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So if b contains 'kittens' make a's value equal 'bar', otherwise keep it 'foo'.  Is this possible?  As it stands now a only ever has a value when b contains 'kittens'.&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
Kevin&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jul 2011 17:03:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Reassign-or-keep-variable-in-eval-s-IF-statement/m-p/50623#M12175</guid>
      <dc:creator>kevintelford</dc:creator>
      <dc:date>2011-07-29T17:03:43Z</dc:date>
    </item>
    <item>
      <title>Re: Reassign (or keep) variable in eval's IF statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Reassign-or-keep-variable-in-eval-s-IF-statement/m-p/50624#M12176</link>
      <description>&lt;P&gt;well it seems it should work, so I went to my code to see how I implemented it, I ended up using a &lt;A href="http://www.splunk.com/base/Documentation/4.1.5/SearchReference/CommonEvalFunctions"&gt;case&lt;/A&gt; command with the last expression as 1==1.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; eval a=case(match(b, "kittens"), "bar", 1==1,a)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It seems that I had the same issue also, and this was how I was able to get it to work.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jul 2011 17:30:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Reassign-or-keep-variable-in-eval-s-IF-statement/m-p/50624#M12176</guid>
      <dc:creator>fk319</dc:creator>
      <dc:date>2011-07-29T17:30:14Z</dc:date>
    </item>
    <item>
      <title>Re: Reassign (or keep) variable in eval's IF statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Reassign-or-keep-variable-in-eval-s-IF-statement/m-p/50625#M12177</link>
      <description>&lt;P&gt;Cool deal, too bad it doesn't work with if as well, but this will do just fine.  Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jul 2011 17:51:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Reassign-or-keep-variable-in-eval-s-IF-statement/m-p/50625#M12177</guid>
      <dc:creator>kevintelford</dc:creator>
      <dc:date>2011-07-29T17:51:21Z</dc:date>
    </item>
  </channel>
</rss>

