<?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 issue in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/foreach-issue/m-p/205982#M59914</link>
    <description>&lt;P&gt;If you have fields called 'A', 'B', and 'C', then &lt;CODE&gt;foreach IM_* ...&lt;/CODE&gt; will not match on them.  Perhaps there is another way to accomplish your goal if you'll tell us what you want to do.&lt;/P&gt;</description>
    <pubDate>Mon, 26 Oct 2015 15:08:53 GMT</pubDate>
    <dc:creator>richgalloway</dc:creator>
    <dc:date>2015-10-26T15:08:53Z</dc:date>
    <item>
      <title>foreach issue</title>
      <link>https://community.splunk.com/t5/Splunk-Search/foreach-issue/m-p/205980#M59912</link>
      <description>&lt;P&gt;Hi, &lt;/P&gt;

&lt;P&gt;Can FOREACH commnad can read text value ?  I am having issue to create new columns&lt;BR /&gt;
foreach IM_* [eval TYPE='&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;']&lt;/P&gt;

&lt;P&gt;So if columns name are A, B ,C .... I would like to create eval expression eval TYPE= A eval TYPE = B and so on...which create automatically instead of creating them one by one.&lt;/P&gt;

&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Mon, 26 Oct 2015 14:34:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/foreach-issue/m-p/205980#M59912</guid>
      <dc:creator>akawacz</dc:creator>
      <dc:date>2015-10-26T14:34:15Z</dc:date>
    </item>
    <item>
      <title>Re: foreach issue</title>
      <link>https://community.splunk.com/t5/Splunk-Search/foreach-issue/m-p/205981#M59913</link>
      <description>&lt;P&gt;I cannot make sense of your question as it is written.  It will &lt;EM&gt;REALLY&lt;/EM&gt; help if you give an example dataset and also an example of desired final output.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Oct 2015 14:46:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/foreach-issue/m-p/205981#M59913</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-10-26T14:46:44Z</dc:date>
    </item>
    <item>
      <title>Re: foreach issue</title>
      <link>https://community.splunk.com/t5/Splunk-Search/foreach-issue/m-p/205982#M59914</link>
      <description>&lt;P&gt;If you have fields called 'A', 'B', and 'C', then &lt;CODE&gt;foreach IM_* ...&lt;/CODE&gt; will not match on them.  Perhaps there is another way to accomplish your goal if you'll tell us what you want to do.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Oct 2015 15:08:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/foreach-issue/m-p/205982#M59914</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2015-10-26T15:08:53Z</dc:date>
    </item>
    <item>
      <title>Re: foreach issue</title>
      <link>https://community.splunk.com/t5/Splunk-Search/foreach-issue/m-p/205983#M59915</link>
      <description>&lt;P&gt;Hi &lt;BR /&gt;
Sorry for not clear explanation. I have just figured out myself&lt;/P&gt;

&lt;P&gt;My point was to create two new fileds :&lt;BR /&gt;
FLAG- is showing  how many fileds are populated for some values (1 if it is some value)&lt;BR /&gt;
TYPE - is creating a lot of new fileds with the name of the column&lt;/P&gt;

&lt;P&gt;So i get two new flags fileds FLAG, TYPE&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval TYPE= "" | foreach IM_* [eval TYPE= TYPE.if(isnotnull('&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;'), "&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;#", "")] | makemv delim="#" TYPE | foreach IM_* [eval FLAG=if(isnull(&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;),0,1)]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Oct 2015 16:51:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/foreach-issue/m-p/205983#M59915</guid>
      <dc:creator>akawacz</dc:creator>
      <dc:date>2015-10-26T16:51:24Z</dc:date>
    </item>
    <item>
      <title>Re: foreach issue</title>
      <link>https://community.splunk.com/t5/Splunk-Search/foreach-issue/m-p/205984#M59916</link>
      <description>&lt;P&gt;Please accept your answer so others who have a similar problem in the future can find it.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Oct 2015 17:01:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/foreach-issue/m-p/205984#M59916</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2015-10-26T17:01:31Z</dc:date>
    </item>
    <item>
      <title>Re: foreach issue</title>
      <link>https://community.splunk.com/t5/Splunk-Search/foreach-issue/m-p/205985#M59917</link>
      <description>&lt;P&gt;I edited your answer to fix some &lt;CODE&gt;markdown&lt;/CODE&gt; problems but I am not sure that I got it correct so please do double-check before clicking "Accept".  I am pretty sure that your &lt;CODE&gt;FLAG&lt;/CODE&gt; part is wrong because the assignment is overwriting itself every time so you are only getting the effect of the last field.  Perhaps you meant this?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval TYPE= "" | foreach IM_* [eval TYPE= TYPE.if(isnotnull('&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;'), "&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;#", "")] | makemv delim="#" TYPE | foreach IM_* [eval FLAG=FLAG + if(isnull(&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;),0,1)]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Oct 2015 17:28:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/foreach-issue/m-p/205985#M59917</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-10-26T17:28:57Z</dc:date>
    </item>
    <item>
      <title>Re: foreach issue</title>
      <link>https://community.splunk.com/t5/Splunk-Search/foreach-issue/m-p/205986#M59918</link>
      <description>&lt;P&gt;it is happening like you said. Last value is shown in the FLAG.  I was trying to add this part what you mentioned but unfortunately is not working. &lt;/P&gt;

&lt;P&gt;However I have made this simpler. I have changed FLAG eval expression. Results are expected (Now it is showing me how many values are in the every column. )&lt;BR /&gt;
Previous version also works but second FOREACH statement did not do anything- all job is done in status - count)&lt;/P&gt;

&lt;P&gt;eval TYPE= "" | foreach IM_* [eval TYPE= TYPE.if(isnotnull('&amp;lt;&amp;gt;'), "&amp;lt;&amp;gt;#", "")] | makemv delim="#" TYPE |&lt;BR /&gt;
 eval FLAG="FLAG" | stats count(FLAG) as COUNT by TYPE,  REPORT_PERIOD&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 07:40:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/foreach-issue/m-p/205986#M59918</guid>
      <dc:creator>akawacz</dc:creator>
      <dc:date>2020-09-29T07:40:49Z</dc:date>
    </item>
  </channel>
</rss>

