<?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 dynamically compare and come up with new fields in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-dynamically-compare-and-come-up-with-new-fields/m-p/546132#M154794</link>
    <description>&lt;P&gt;hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/231868"&gt;@yoshilog&lt;/a&gt;,&lt;BR /&gt;&lt;BR /&gt;You can use &lt;STRONG&gt;foreach &lt;/STRONG&gt;command with &amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt; instead of &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;. You need to make sure that suffixes of fields &lt;STRONG&gt;a&amp;lt;SUFFIX&amp;gt;&lt;/STRONG&gt; and &lt;STRONG&gt;q&amp;lt;SUFFIX&amp;gt;&lt;/STRONG&gt; should be the same.&lt;BR /&gt;Try this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval afield1=4, afield2=2, afield3=8, afield4=10, qfield1=1, qfield2=2, qfield3=3, qfield4=10 
| foreach a* 
    [ eval r&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;=if(a&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;=q&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;, "EQUAL", "NOT EQUAL")]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If this reply helps you, a like would be appreciated.&lt;/P&gt;</description>
    <pubDate>Wed, 31 Mar 2021 06:24:44 GMT</pubDate>
    <dc:creator>manjunathmeti</dc:creator>
    <dc:date>2021-03-31T06:24:44Z</dc:date>
    <item>
      <title>How to dynamically compare and come up with new fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-dynamically-compare-and-come-up-with-new-fields/m-p/546127#M154792</link>
      <description>&lt;P&gt;Using the extract function, I can arrive with the below columns:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="yoshilog_0-1617169596797.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/13550i412E6477E4B4EDEE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="yoshilog_0-1617169596797.png" alt="yoshilog_0-1617169596797.png" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="yoshilog_1-1617169642386.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/13551i190FF88A03967D48/image-size/medium?v=v2&amp;amp;px=400" role="button" title="yoshilog_1-1617169642386.png" alt="yoshilog_1-1617169642386.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to compare the values, and come up with a new field like r1, r2, r3 which says whether it's same or not.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm thinking of using eval function and then if statements to compare the two values but I'm not sure how to do it in such a way that will apply to all columns with titles beginning with "q" and "a".&lt;/P&gt;&lt;P&gt;I was thinking of using foreach loop but it seems that the foreach loop has very specific usecases that doesn't apply to mine.&lt;/P&gt;&lt;P&gt;The dilemma is that I need to do this dynamically, because it's possible that in other rows, there will be data reaching up to q5... q10... etc.&lt;/P&gt;&lt;P&gt;Is there a specific command for what I want to do?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Mar 2021 05:52:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-dynamically-compare-and-come-up-with-new-fields/m-p/546127#M154792</guid>
      <dc:creator>yoshilog</dc:creator>
      <dc:date>2021-03-31T05:52:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to dynamically compare and come up with new fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-dynamically-compare-and-come-up-with-new-fields/m-p/546132#M154794</link>
      <description>&lt;P&gt;hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/231868"&gt;@yoshilog&lt;/a&gt;,&lt;BR /&gt;&lt;BR /&gt;You can use &lt;STRONG&gt;foreach &lt;/STRONG&gt;command with &amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt; instead of &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;. You need to make sure that suffixes of fields &lt;STRONG&gt;a&amp;lt;SUFFIX&amp;gt;&lt;/STRONG&gt; and &lt;STRONG&gt;q&amp;lt;SUFFIX&amp;gt;&lt;/STRONG&gt; should be the same.&lt;BR /&gt;Try this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval afield1=4, afield2=2, afield3=8, afield4=10, qfield1=1, qfield2=2, qfield3=3, qfield4=10 
| foreach a* 
    [ eval r&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;=if(a&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;=q&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;, "EQUAL", "NOT EQUAL")]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If this reply helps you, a like would be appreciated.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Mar 2021 06:24:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-dynamically-compare-and-come-up-with-new-fields/m-p/546132#M154794</guid>
      <dc:creator>manjunathmeti</dc:creator>
      <dc:date>2021-03-31T06:24:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to dynamically compare and come up with new fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-dynamically-compare-and-come-up-with-new-fields/m-p/546186#M154818</link>
      <description>&lt;P&gt;Building on&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/129090"&gt;@manjunathmeti&lt;/a&gt;&amp;nbsp;reply, to avoid having to deal with 'a' fields that are not part of your checking, you can use foreach like this, where &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; is the number in the foreach comand&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval n=mvrange(1,51)
| eval Results="Yes,No"
| mvexpand n
| eval a{n}=mvindex(split(Results,","), random() % 2)
| eval q{n}=mvindex(split(Results,","), random() % 2)
| stats values(a*) as a* values(q*) as q*
| foreach 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 [
  eval r&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=if(a&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=q&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;, "Equal", "Not Equal") 
]&lt;/LI-CODE&gt;&lt;P&gt;This creates 50 fields with a random a/q yes/no variant then compares each of them&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Mar 2021 09:40:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-dynamically-compare-and-come-up-with-new-fields/m-p/546186#M154818</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2021-03-31T09:40:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to dynamically compare and come up with new fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-dynamically-compare-and-come-up-with-new-fields/m-p/546646#M154962</link>
      <description>&lt;P&gt;Thank you for creating a dynamic example! It worked.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Apr 2021 02:49:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-dynamically-compare-and-come-up-with-new-fields/m-p/546646#M154962</guid>
      <dc:creator>yoshilog</dc:creator>
      <dc:date>2021-04-05T02:49:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to dynamically compare and come up with new fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-dynamically-compare-and-come-up-with-new-fields/m-p/546648#M154963</link>
      <description>&lt;P&gt;Thank you for sharing. It worked!&lt;/P&gt;</description>
      <pubDate>Mon, 05 Apr 2021 02:49:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-dynamically-compare-and-come-up-with-new-fields/m-p/546648#M154963</guid>
      <dc:creator>yoshilog</dc:creator>
      <dc:date>2021-04-05T02:49:35Z</dc:date>
    </item>
  </channel>
</rss>

