<?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: {} equivalent on right hand side of eval in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/equivalent-on-right-hand-side-of-eval/m-p/578007#M201429</link>
    <description>&lt;P&gt;Ugly but should work. Use foreach.&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;PRE&gt;| makeresults count=3&lt;BR /&gt;| eval a1=2,a2=5,a3=8&lt;BR /&gt;| streamstats count&lt;BR /&gt;| foreach a* &lt;BR /&gt;   [ eval result=if (&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt; = count,&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;,result)]&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Adjust to your needs (make the condition reference current year) and you're good to go.&lt;/P&gt;</description>
    <pubDate>Fri, 10 Dec 2021 13:09:28 GMT</pubDate>
    <dc:creator>PickleRick</dc:creator>
    <dc:date>2021-12-10T13:09:28Z</dc:date>
    <item>
      <title>{} equivalent on right hand side of eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/equivalent-on-right-hand-side-of-eval/m-p/577999#M201423</link>
      <description>&lt;P&gt;I hate hardcoding dynamic things. Sooner or later those thing break.&amp;nbsp;I have data with fields&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;... forecast_2020=400, forecast_2021=500, forecast_2022=650, forecast_2023=800 ...&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and in some search I need to use the correct forecast for the current year.&lt;/P&gt;&lt;P&gt;What I could do is&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;...
| eval year=strftime(now(),"%Y"),
       forecast=case(year==2021, forecast_2021,
                     year==2022, forecast_2022,
                     year==2023, forecast_2023,
                     1==1,       0)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This definitely results in problems in 2024; by then I will have a field &lt;FONT face="courier new,courier"&gt;forecast_2024&lt;/FONT&gt; but nobody will remember to update&amp;nbsp;the search.&lt;/P&gt;&lt;P&gt;I'd rather use something along these lines:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;...
| eval year=strftime(now(),"%Y"),
       forecast=coalesce(forecast_{year}, 0)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, the {} trick can only be used on the left hand side in eval.&amp;nbsp;Is there any similar cool trick which works on the right hand side?&lt;/P&gt;</description>
      <pubDate>Fri, 10 Dec 2021 12:36:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/equivalent-on-right-hand-side-of-eval/m-p/577999#M201423</guid>
      <dc:creator>usd0872</dc:creator>
      <dc:date>2021-12-10T12:36:14Z</dc:date>
    </item>
    <item>
      <title>Re: {} equivalent on right hand side of eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/equivalent-on-right-hand-side-of-eval/m-p/578005#M201427</link>
      <description>&lt;P&gt;Not exactly since it still uses {} on the left, but using foreach you could do this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval year=strftime(now(),"%Y")
| eval forecast_2021=random()%100


| eval year_{year}=year
| foreach year_*
    [| eval forecast=coalesce(forecast_&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;,0)]&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 10 Dec 2021 12:38:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/equivalent-on-right-hand-side-of-eval/m-p/578005#M201427</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2021-12-10T12:38:59Z</dc:date>
    </item>
    <item>
      <title>Re: {} equivalent on right hand side of eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/equivalent-on-right-hand-side-of-eval/m-p/578007#M201429</link>
      <description>&lt;P&gt;Ugly but should work. Use foreach.&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;PRE&gt;| makeresults count=3&lt;BR /&gt;| eval a1=2,a2=5,a3=8&lt;BR /&gt;| streamstats count&lt;BR /&gt;| foreach a* &lt;BR /&gt;   [ eval result=if (&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt; = count,&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;,result)]&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Adjust to your needs (make the condition reference current year) and you're good to go.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Dec 2021 13:09:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/equivalent-on-right-hand-side-of-eval/m-p/578007#M201429</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2021-12-10T13:09:28Z</dc:date>
    </item>
    <item>
      <title>Re: {} equivalent on right hand side of eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/equivalent-on-right-hand-side-of-eval/m-p/578020#M201434</link>
      <description>&lt;P&gt;Bingo! A good way to achieve the result. It fits my need perfectly, I just could not think of it myself. Thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Dec 2021 14:15:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/equivalent-on-right-hand-side-of-eval/m-p/578020#M201434</guid>
      <dc:creator>usd0872</dc:creator>
      <dc:date>2021-12-10T14:15:43Z</dc:date>
    </item>
    <item>
      <title>Re: {} equivalent on right hand side of eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/equivalent-on-right-hand-side-of-eval/m-p/578021#M201435</link>
      <description>&lt;P&gt;Yep, &lt;FONT face="courier new,courier"&gt;foreach&lt;/FONT&gt; is the way to solve this. Thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Dec 2021 14:19:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/equivalent-on-right-hand-side-of-eval/m-p/578021#M201435</guid>
      <dc:creator>usd0872</dc:creator>
      <dc:date>2021-12-10T14:19:09Z</dc:date>
    </item>
  </channel>
</rss>

