<?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: foreach with Error in 'eval' command in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/foreach-with-Error-in-eval-command/m-p/319977#M95632</link>
    <description>&lt;P&gt;@kennethyeung, the documentation has different examples to explain these points.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;&amp;lt;&amp;lt;field&amp;gt;&amp;gt;&lt;/CODE&gt;: Replaces the entire field&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;&lt;/CODE&gt;: This is a part of the field which you can identify by replacing &lt;CODE&gt;asterisk (*)&lt;/CODE&gt; in foreach i.e.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;| foreach code*&lt;/CODE&gt; implies &lt;CODE&gt;&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;&lt;/CODE&gt; will find &lt;CODE&gt;1&lt;/CODE&gt; and &lt;CODE&gt;2&lt;/CODE&gt; from fields &lt;CODE&gt;code1&lt;/CODE&gt; and &lt;CODE&gt;code2&lt;/CODE&gt; respectively.&lt;/P&gt;</description>
    <pubDate>Tue, 05 Dec 2017 12:44:31 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2017-12-05T12:44:31Z</dc:date>
    <item>
      <title>foreach with Error in 'eval' command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/foreach-with-Error-in-eval-command/m-p/319971#M95626</link>
      <description>&lt;P&gt;below my se&lt;BR /&gt;
index=test code IN (1,3) &lt;BR /&gt;
| eval code1=1 &lt;BR /&gt;
| eval close_1=10&lt;BR /&gt;
 | eval close_2=5&lt;BR /&gt;
|  eval code2=3&lt;BR /&gt;
| foreach code* [eval p_code_--FIELD--=close/close_$--FIELD--$]&lt;/P&gt;

&lt;P&gt;i want to have p_code_1 =close/close_1 and p_code_2=close/close_2&lt;/P&gt;

&lt;P&gt;I found out i cannot post &amp;lt;&amp;lt; Field &amp;gt;&amp;gt; and use --FIELD-- to replaice&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 17:03:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/foreach-with-Error-in-eval-command/m-p/319971#M95626</guid>
      <dc:creator>kennethyeung</dc:creator>
      <dc:date>2020-09-29T17:03:48Z</dc:date>
    </item>
    <item>
      <title>Re: foreach with Error in 'eval' command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/foreach-with-Error-in-eval-command/m-p/319972#M95627</link>
      <description>&lt;P&gt;hi @kennethyeung,&lt;/P&gt;

&lt;P&gt;can you please use &lt;CODE&gt;101010&lt;/CODE&gt; (code sample) to pose search or code ??&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2017 09:02:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/foreach-with-Error-in-eval-command/m-p/319972#M95627</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2017-12-05T09:02:24Z</dc:date>
    </item>
    <item>
      <title>Re: foreach with Error in 'eval' command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/foreach-with-Error-in-eval-command/m-p/319973#M95628</link>
      <description>&lt;P&gt;@kennethyeung, please try the following, as per your requirement for fields &lt;CODE&gt;p_code_1="close/close_1" and p_code_2="close/close_2"&lt;/CODE&gt;, you should use &lt;CODE&gt;&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;&lt;/CODE&gt; instead of &lt;CODE&gt;&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;&lt;/CODE&gt; value in foreach eval statement should be in double quotes:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| fields - _time
| eval code1=1 
| eval close_1=10
| eval close_2=5
| eval code2=3
| foreach code* [eval p_code_&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;="close/close_&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;"]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Dec 2017 09:22:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/foreach-with-Error-in-eval-command/m-p/319973#M95628</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-12-05T09:22:29Z</dc:date>
    </item>
    <item>
      <title>Re: foreach with Error in 'eval' command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/foreach-with-Error-in-eval-command/m-p/319974#M95629</link>
      <description>&lt;P&gt;may i know that when use field and when use matchstr?&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2017 09:43:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/foreach-with-Error-in-eval-command/m-p/319974#M95629</guid>
      <dc:creator>kennethyeung</dc:creator>
      <dc:date>2017-12-05T09:43:19Z</dc:date>
    </item>
    <item>
      <title>Re: foreach with Error in 'eval' command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/foreach-with-Error-in-eval-command/m-p/319975#M95630</link>
      <description>&lt;P&gt;@niketnilay want to ask,  is it possible foreach lilke other script?&lt;BR /&gt;
for example&lt;/P&gt;

&lt;P&gt;in my previous search, i need to create eval code1=1, code2=3,&lt;BR /&gt;
but actually the result is from In (1,3)&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2017 10:11:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/foreach-with-Error-in-eval-command/m-p/319975#M95630</guid>
      <dc:creator>kennethyeung</dc:creator>
      <dc:date>2017-12-05T10:11:06Z</dc:date>
    </item>
    <item>
      <title>Re: foreach with Error in 'eval' command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/foreach-with-Error-in-eval-command/m-p/319976#M95631</link>
      <description>&lt;P&gt;Please replace the foreach command with the following &lt;CODE&gt;'&amp;lt;&amp;lt;field&amp;gt;&amp;gt;'&lt;/CODE&gt; should replace the selected field value:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| foreach code* [eval p_code_&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;="close/close_".'&amp;lt;&amp;lt;field&amp;gt;&amp;gt;']
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Dec 2017 12:40:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/foreach-with-Error-in-eval-command/m-p/319976#M95631</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-12-05T12:40:58Z</dc:date>
    </item>
    <item>
      <title>Re: foreach with Error in 'eval' command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/foreach-with-Error-in-eval-command/m-p/319977#M95632</link>
      <description>&lt;P&gt;@kennethyeung, the documentation has different examples to explain these points.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;&amp;lt;&amp;lt;field&amp;gt;&amp;gt;&lt;/CODE&gt;: Replaces the entire field&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;&lt;/CODE&gt;: This is a part of the field which you can identify by replacing &lt;CODE&gt;asterisk (*)&lt;/CODE&gt; in foreach i.e.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;| foreach code*&lt;/CODE&gt; implies &lt;CODE&gt;&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;&lt;/CODE&gt; will find &lt;CODE&gt;1&lt;/CODE&gt; and &lt;CODE&gt;2&lt;/CODE&gt; from fields &lt;CODE&gt;code1&lt;/CODE&gt; and &lt;CODE&gt;code2&lt;/CODE&gt; respectively.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2017 12:44:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/foreach-with-Error-in-eval-command/m-p/319977#M95632</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-12-05T12:44:31Z</dc:date>
    </item>
    <item>
      <title>Re: foreach with Error in 'eval' command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/foreach-with-Error-in-eval-command/m-p/319978#M95633</link>
      <description>&lt;P&gt;Thanks you your explaination &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Dec 2017 02:20:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/foreach-with-Error-in-eval-command/m-p/319978#M95633</guid>
      <dc:creator>kennethyeung</dc:creator>
      <dc:date>2017-12-06T02:20:46Z</dc:date>
    </item>
  </channel>
</rss>

