<?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 Not Working in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Foreach-Not-Working/m-p/399681#M115863</link>
    <description>&lt;P&gt;@IRHM73 &lt;/P&gt;

&lt;P&gt;Can you please share sample event and expected output?&lt;/P&gt;</description>
    <pubDate>Fri, 05 Apr 2019 09:26:00 GMT</pubDate>
    <dc:creator>kamlesh_vaghela</dc:creator>
    <dc:date>2019-04-05T09:26:00Z</dc:date>
    <item>
      <title>Foreach Not Working</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Foreach-Not-Working/m-p/399680#M115862</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I wonder whether someone can help me please.&lt;/P&gt;

&lt;P&gt;I've put together the following query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;`real-time-information_wmf(ServiceRequestReceived)` 
| rex field=detail.filterFields "\((?&amp;lt;myField&amp;gt;.*)\)" 
| makemv myField 
| mvexpand myField
| makemv delim="," myField
| eval wibble {myField}=myField
| eval header=""
| foreach wibble* [eval header=header+'&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;']
| chart sum(wibble*) as wibble* by _time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;There are a couple of issues with this.&lt;/P&gt;

&lt;P&gt;On the eval wibble line, the new field has a comma added to the field name, even though it's been removed on the makemv line.&lt;/P&gt;

&lt;P&gt;Then the second and most important issue is that when I run the query, the chart only shows the 'wibble fieldnames.&lt;/P&gt;

&lt;P&gt;I just wondered whether someone could look at this please and let me know where I've gone wrong.&lt;/P&gt;

&lt;P&gt;Many thanks and kind regards&lt;/P&gt;

&lt;P&gt;Chris&lt;/P&gt;</description>
      <pubDate>Fri, 05 Apr 2019 09:15:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Foreach-Not-Working/m-p/399680#M115862</guid>
      <dc:creator>IRHM73</dc:creator>
      <dc:date>2019-04-05T09:15:29Z</dc:date>
    </item>
    <item>
      <title>Re: Foreach Not Working</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Foreach-Not-Working/m-p/399681#M115863</link>
      <description>&lt;P&gt;@IRHM73 &lt;/P&gt;

&lt;P&gt;Can you please share sample event and expected output?&lt;/P&gt;</description>
      <pubDate>Fri, 05 Apr 2019 09:26:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Foreach-Not-Working/m-p/399681#M115863</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2019-04-05T09:26:00Z</dc:date>
    </item>
    <item>
      <title>Re: Foreach Not Working</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Foreach-Not-Working/m-p/399682#M115864</link>
      <description>&lt;P&gt;Hi @kamlesh_vaghela.&lt;/P&gt;

&lt;P&gt;Thank you for getting in touch with me, and I'm so sorry it's taken some time to come back to you.&lt;/P&gt;

&lt;P&gt;I have come up with the following solution:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;`real-time-information_wmf(ServiceRequestReceived)` 
| rex field=detail.filterFields "\((?&amp;lt;Fields&amp;gt;.*)\)" 
| makemv Fields 
| makemv delim="," Fields 
| mvexpand Fields
| eval nField {Fields}=Fields
| foreach nField* [eval &amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt; = '&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;']
| chart values(detail.serviceName) AS "Service Name" count(nField*) as * by _time 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Many thanks and kind regards&lt;/P&gt;

&lt;P&gt;Chris&lt;/P&gt;</description>
      <pubDate>Thu, 11 Apr 2019 05:42:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Foreach-Not-Working/m-p/399682#M115864</guid>
      <dc:creator>IRHM73</dc:creator>
      <dc:date>2019-04-11T05:42:44Z</dc:date>
    </item>
    <item>
      <title>Re: Foreach Not Working</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Foreach-Not-Working/m-p/399683#M115865</link>
      <description>&lt;P&gt;@IRHM73 &lt;/P&gt;

&lt;P&gt;Great. Please accept your answer.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Apr 2019 06:15:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Foreach-Not-Working/m-p/399683#M115865</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2019-04-11T06:15:19Z</dc:date>
    </item>
  </channel>
</rss>

