<?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 make  'for loop' in splunk query in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/how-to-make-for-loop-in-splunk-query/m-p/440596#M171495</link>
    <description>&lt;P&gt;'MuS' thank you&lt;BR /&gt;
but i think that did not communicate my problem in sufficient quantity.&lt;/P&gt;

&lt;P&gt;My final purpose is factor1 grouping.&lt;BR /&gt;
I want somebody see before / after search result and  code.&lt;/P&gt;

&lt;P&gt;*befor search result&lt;BR /&gt;
factor1 |   factor1_hierarchy_flag  |   factor1_hierarchy_level |   factor1_min |   factor1_max&lt;BR /&gt;
num1    |   NumA    |   100 |   NumB    |   NumC&lt;BR /&gt;
num2    |   NumA    |   100 |   NumB    |   NumC&lt;BR /&gt;
num3    |   NumA    |   100 |   NumB    |   NumC&lt;BR /&gt;
num4    |   NumA    |   100 |   NumB    |   NumC&lt;BR /&gt;
num5    |   NumA    |   100 |   NumB    |   NumC&lt;BR /&gt;
num6    |   NumA    |   100 |   NumB    |   NumC&lt;BR /&gt;
num7    |   NumA    |   100 |   NumB    |   NumC&lt;BR /&gt;
num8    |   NumA    |   100 |   NumB    |   NumC&lt;BR /&gt;
num9    |   NumA    |   100 |   NumB    |   NumC&lt;BR /&gt;
num10   |   NumA    |   100 |   NumB    |   NumC&lt;BR /&gt;
… |   … |   … |   … |   …&lt;/P&gt;

&lt;P&gt;*wanted query&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;factor1_hierarchy_level = 100
factor1_refference_value = 'one of all factor1 number'    

    for(i=1, i&amp;lt;=factor1_hierarchy_level, i=i+1)
    {
        factor1_prev=factor1_min+factor1_hierarchy_flag*(i-1)
        factor1_next=factor1_min+factor1_hierarchy_flag*(i)

        case(factor1_prev&amp;lt;factor1_refference_value&amp;lt;factor1_next)
        factor1_grouping=i
        case(factor1_pv&amp;gt;factor1_max)
        return 0
     }
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;*after search result(grouping colunm creating)&lt;BR /&gt;
factor1 |   factor1_hierarchy_flag  |   factor1_hierarchy_level |   factor1_min |   factor1_max |   factor1_grouping&lt;BR /&gt;
num1    |   NumA    |   100 |   NumB    |   NumC    |   one of number from 1 to 100&lt;BR /&gt;
num2    |   NumA    |   100 |   NumB    |   NumC    |   one of number from 1 to 100&lt;BR /&gt;
num3    |   NumA    |   100 |   NumB    |   NumC    |   one of number from 1 to 100&lt;BR /&gt;
num4    |   NumA    |   100 |   NumB    |   NumC    |   one of number from 1 to 100&lt;BR /&gt;
num5    |   NumA    |   100 |   NumB    |   NumC    |   one of number from 1 to 100&lt;BR /&gt;
num6    |   NumA    |   100 |   NumB    |   NumC    |   one of number from 1 to 100&lt;BR /&gt;
num7    |   NumA    |   100 |   NumB    |   NumC    |   one of number from 1 to 100&lt;BR /&gt;
num8    |   NumA    |   100 |   NumB    |   NumC    |   one of number from 1 to 100&lt;BR /&gt;
num9    |   NumA    |   100 |   NumB    |   NumC    |   one of number from 1 to 100&lt;BR /&gt;
num10   |   NumA    |   100 |   NumB    |   NumC    |   one of number from 1 to 100&lt;BR /&gt;
… |   … |   … |   … |   … |   …&lt;/P&gt;</description>
    <pubDate>Wed, 30 Sep 2020 00:28:08 GMT</pubDate>
    <dc:creator>leejaeyong</dc:creator>
    <dc:date>2020-09-30T00:28:08Z</dc:date>
    <item>
      <title>how to make  'for loop' in splunk query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-make-for-loop-in-splunk-query/m-p/440594#M171493</link>
      <description>&lt;P&gt;For all row, how can i make splunk query following  'for loop'?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;for(i=1, i&amp;lt;100, i=i+1)
{
    factor1_prev=factor1_min+factor1_hierarchy_flag*(i-1)
    factor1_pv=factor1_min+factor1_hierarchy_flag*i
    factor1_next=factor1_min+factor1_hierarchy_flag*(i+1)

    case(factor1_prev&amp;lt;factor1_pv&amp;lt;factor1_next)
    factor1_hierarchy=i
    case(factor1_pv&amp;gt;factor1_max)
    return 0
}
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 May 2019 05:44:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-make-for-loop-in-splunk-query/m-p/440594#M171493</guid>
      <dc:creator>leejaeyong</dc:creator>
      <dc:date>2019-05-07T05:44:17Z</dc:date>
    </item>
    <item>
      <title>Re: how to make  'for loop' in splunk query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-make-for-loop-in-splunk-query/m-p/440595#M171494</link>
      <description>&lt;P&gt;Hi leejaeyong,&lt;/P&gt;

&lt;P&gt;you can try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=100 
| streamstats count AS foo 
| eval factor1_min=(random() % 100) /2, factor1_hierarchy_flag=(random() % 100) +2 
| rename comment AS "This ^^^ just creates dummy data" 
| eval factor1_prev=factor1_min+factor1_hierarchy_flag*(foo-1),
    factor1_pv=factor1_min+factor1_hierarchy_flag*foo,
    factor1_next=factor1_min+factor1_hierarchy_flag*(foo+1),
    factor1_hierarchy=case(factor1_prev &amp;lt; factor1_pv AND factor1_pv &amp;lt;factor1_next, foo, factor1_pv&amp;gt;factor1_max, 0, true(), "unknonw")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Everything up until the &lt;CODE&gt;rename&lt;/CODE&gt; command creates just dummy events, and the last &lt;CODE&gt;eval&lt;/CODE&gt; will be your loop over the 100 events. In this example &lt;CODE&gt;foo&lt;/CODE&gt; is your &lt;CODE&gt;i&lt;/CODE&gt; in your code.&lt;/P&gt;

&lt;P&gt;Hope this helps ...&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;

&lt;P&gt;PS: I noticed that in your example &lt;CODE&gt;factor1_max&lt;/CODE&gt; is missing that's why the last &lt;CODE&gt;case()&lt;/CODE&gt; statement never will match.&lt;/P&gt;</description>
      <pubDate>Wed, 08 May 2019 03:40:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-make-for-loop-in-splunk-query/m-p/440595#M171494</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2019-05-08T03:40:32Z</dc:date>
    </item>
    <item>
      <title>Re: how to make  'for loop' in splunk query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-make-for-loop-in-splunk-query/m-p/440596#M171495</link>
      <description>&lt;P&gt;'MuS' thank you&lt;BR /&gt;
but i think that did not communicate my problem in sufficient quantity.&lt;/P&gt;

&lt;P&gt;My final purpose is factor1 grouping.&lt;BR /&gt;
I want somebody see before / after search result and  code.&lt;/P&gt;

&lt;P&gt;*befor search result&lt;BR /&gt;
factor1 |   factor1_hierarchy_flag  |   factor1_hierarchy_level |   factor1_min |   factor1_max&lt;BR /&gt;
num1    |   NumA    |   100 |   NumB    |   NumC&lt;BR /&gt;
num2    |   NumA    |   100 |   NumB    |   NumC&lt;BR /&gt;
num3    |   NumA    |   100 |   NumB    |   NumC&lt;BR /&gt;
num4    |   NumA    |   100 |   NumB    |   NumC&lt;BR /&gt;
num5    |   NumA    |   100 |   NumB    |   NumC&lt;BR /&gt;
num6    |   NumA    |   100 |   NumB    |   NumC&lt;BR /&gt;
num7    |   NumA    |   100 |   NumB    |   NumC&lt;BR /&gt;
num8    |   NumA    |   100 |   NumB    |   NumC&lt;BR /&gt;
num9    |   NumA    |   100 |   NumB    |   NumC&lt;BR /&gt;
num10   |   NumA    |   100 |   NumB    |   NumC&lt;BR /&gt;
… |   … |   … |   … |   …&lt;/P&gt;

&lt;P&gt;*wanted query&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;factor1_hierarchy_level = 100
factor1_refference_value = 'one of all factor1 number'    

    for(i=1, i&amp;lt;=factor1_hierarchy_level, i=i+1)
    {
        factor1_prev=factor1_min+factor1_hierarchy_flag*(i-1)
        factor1_next=factor1_min+factor1_hierarchy_flag*(i)

        case(factor1_prev&amp;lt;factor1_refference_value&amp;lt;factor1_next)
        factor1_grouping=i
        case(factor1_pv&amp;gt;factor1_max)
        return 0
     }
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;*after search result(grouping colunm creating)&lt;BR /&gt;
factor1 |   factor1_hierarchy_flag  |   factor1_hierarchy_level |   factor1_min |   factor1_max |   factor1_grouping&lt;BR /&gt;
num1    |   NumA    |   100 |   NumB    |   NumC    |   one of number from 1 to 100&lt;BR /&gt;
num2    |   NumA    |   100 |   NumB    |   NumC    |   one of number from 1 to 100&lt;BR /&gt;
num3    |   NumA    |   100 |   NumB    |   NumC    |   one of number from 1 to 100&lt;BR /&gt;
num4    |   NumA    |   100 |   NumB    |   NumC    |   one of number from 1 to 100&lt;BR /&gt;
num5    |   NumA    |   100 |   NumB    |   NumC    |   one of number from 1 to 100&lt;BR /&gt;
num6    |   NumA    |   100 |   NumB    |   NumC    |   one of number from 1 to 100&lt;BR /&gt;
num7    |   NumA    |   100 |   NumB    |   NumC    |   one of number from 1 to 100&lt;BR /&gt;
num8    |   NumA    |   100 |   NumB    |   NumC    |   one of number from 1 to 100&lt;BR /&gt;
num9    |   NumA    |   100 |   NumB    |   NumC    |   one of number from 1 to 100&lt;BR /&gt;
num10   |   NumA    |   100 |   NumB    |   NumC    |   one of number from 1 to 100&lt;BR /&gt;
… |   … |   … |   … |   … |   …&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 00:28:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-make-for-loop-in-splunk-query/m-p/440596#M171495</guid>
      <dc:creator>leejaeyong</dc:creator>
      <dc:date>2020-09-30T00:28:08Z</dc:date>
    </item>
  </channel>
</rss>

