<?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: How to use Foreach using multiple columns? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-Foreach-using-multiple-columns/m-p/401281#M116177</link>
    <description>&lt;P&gt;Glad to help you.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Happy Splunking&lt;/STRONG&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 22 Jun 2018 14:55:56 GMT</pubDate>
    <dc:creator>kamlesh_vaghela</dc:creator>
    <dc:date>2018-06-22T14:55:56Z</dc:date>
    <item>
      <title>How to use Foreach using multiple columns?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-Foreach-using-multiple-columns/m-p/401278#M116174</link>
      <description>&lt;P&gt;Hello there,&lt;/P&gt;

&lt;P&gt;I am having a hard time figuring out how to use / how is working foreach + eval.&lt;/P&gt;

&lt;P&gt;I have something like :&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/5259i5209C3F2F0D9471E/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Which can be obtained using this search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval a="test"
| eval result_a_version_1=1
| eval result_a_version_2=3
| eval result_b_version_1=5
| eval result_b_version_2=2
| fields - _time
| table a result_a_version_1 result_b_version_1 result_a_version_2 result_b_version_2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And I am trying to use foreach/eval to get this :&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/5260i7E02392C32AF8F43/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Matching search :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval a="test"
| eval result_a_version_1=1
| eval result_a_version_2=3
| eval result_b_version_1=5
| eval result_b_version_2=2
| fields - _time
| eval tota_a_b_version_1=result_a_version_1+result_b_version_1
| eval tota_a_b_version_2=result_a_version_2+result_b_version_2
| table a result_a_version_1 result_b_version_1 tota_a_b_version_1 result_a_version_2 result_b_version_2 tota_a_b_version_2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;As the version number can vary, I am guessing I have to use foreach somehow.&lt;/P&gt;

&lt;P&gt;Thanks in advance for any tip!&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jun 2018 11:21:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-Foreach-using-multiple-columns/m-p/401278#M116174</guid>
      <dc:creator>D2SI</dc:creator>
      <dc:date>2018-06-22T11:21:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Foreach using multiple columns?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-Foreach-using-multiple-columns/m-p/401279#M116175</link>
      <description>&lt;P&gt;Hi @D2SI,&lt;/P&gt;

&lt;P&gt;I'm able to total of similar version. Can you please try the following search. I'm still working on the field name.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval test="test" 
| eval result_a_version_1=1 
| eval result_a_version_2=3 
| eval result_b_version_1=5 
| eval result_b_version_2=2
| eval result_a_version_3=50 
| eval result_b_version_3=20 
| fields - _time 
| table test result_a_version_1 result_b_version_1 result_a_version_2 result_b_version_2 result_a_version_3 result_b_version_3
| foreach result_*_version_* 
    [ eval total_of_version_&amp;lt;&amp;lt;MATCHSEG2&amp;gt;&amp;gt;=if(isnotnull(total_of_version_&amp;lt;&amp;lt;MATCHSEG2&amp;gt;&amp;gt;),total_of_version_&amp;lt;&amp;lt;MATCHSEG2&amp;gt;&amp;gt;+'&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;','&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;') ] 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jun 2018 12:20:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-Foreach-using-multiple-columns/m-p/401279#M116175</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2018-06-22T12:20:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Foreach using multiple columns?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-Foreach-using-multiple-columns/m-p/401280#M116176</link>
      <description>&lt;P&gt;Seems to be what I was after using MATCHSEG2, thanks a lot !&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jun 2018 14:46:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-Foreach-using-multiple-columns/m-p/401280#M116176</guid>
      <dc:creator>D2SI</dc:creator>
      <dc:date>2018-06-22T14:46:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to use Foreach using multiple columns?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-Foreach-using-multiple-columns/m-p/401281#M116177</link>
      <description>&lt;P&gt;Glad to help you.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Happy Splunking&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jun 2018 14:55:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-Foreach-using-multiple-columns/m-p/401281#M116177</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2018-06-22T14:55:56Z</dc:date>
    </item>
  </channel>
</rss>

