<?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 Filter out all elements of a list which match the first element in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Filter-out-all-elements-of-a-list-which-match-the-first-element/m-p/707648#M239329</link>
    <description>&lt;P&gt;I'm a bit stumped on this problem. Before I jump into the issue, there's a couple of restrictions:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;I'm working in an environment that is running an old version of Splunk which &lt;U&gt;does not&lt;/U&gt; have access to the mvmap() function. Working on getting that updated, but until then I still need to try to get a solution to this problem figured out.&lt;/LI&gt;&lt;LI&gt;This operation is not the only piece of logic I'm trying to accomplish here. Assume there are other unnamed fields which are already in a specifically sorted way which we do not want to disturb.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm attempting to filter out all elements of a list which match the first element, leaving only the elements which are not a match. Here is an example which does work:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval base = split("A75CD,A75AB,A75CD,A75BA,A75DE",",")
| eval mv_to_search=mvindex(base,1,mvcount(base)-1)
| eval search_value=mvindex(base,0)

| eval COMMENT = "ABOVE IS ALL SETUP, BELOW IS ATTEMPTED SOLUTIONS"

| eval filtered_mv=mvfilter(!match(base, "A75CD"))
| eval var_type = typeof(search_value)
| table base, mv_to_search, search_value, filtered_mv, var_type&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, when I attempt to switch it out for something like the following, it does not work:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval base = split("A75CD,A75AB,A75CD,A75BA,A75DE",",")
| eval mv_to_search=mvindex(base,1,mvcount(base)-1)
| eval search_value=mvindex(base,0)

| eval COMMENT = "ABOVE IS ALL SETUP, BELOW IS ATTEMPTED SOLUTIONS"

| eval filtered_mv=mvfilter(!match(base, mvindex(base,0)))
| eval var_type = typeof(search_value)
| table base, mv_to_search, search_value, filtered_mv, var_type&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have even attempted to solve it using a foreach command, but was also unsuccessful:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval base = split("A75CD,A75AB,A75CD,A75BA,A75DE",",")
| eval mv_to_search=mvindex(base,1,mvcount(base)-1)
| eval search_value=mvindex(base,0)

| eval COMMENT = "ABOVE IS ALL SETUP, BELOW IS ATTEMPTED SOLUTIONS"

| foreach mode=multivalue base [eval filtered_mv = if('&amp;lt;&amp;lt;ITEM&amp;gt;&amp;gt;'!=mvindex(base,0), mvappend(filtered_mv,'&amp;lt;&amp;lt;ITEM&amp;gt;&amp;gt;'), filtered_mv)]
| eval var_type = typeof(search_value)
| table base, mv_to_search, search_value, filtered_mv, var_type&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm open to any other ideas which might accomplish this better or more efficiently. Not sure where I'm going wrong with this one, or whether this idea is even possible.&lt;/P&gt;</description>
    <pubDate>Fri, 27 Dec 2024 21:35:55 GMT</pubDate>
    <dc:creator>BG_Splunk</dc:creator>
    <dc:date>2024-12-27T21:35:55Z</dc:date>
    <item>
      <title>Filter out all elements of a list which match the first element</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Filter-out-all-elements-of-a-list-which-match-the-first-element/m-p/707648#M239329</link>
      <description>&lt;P&gt;I'm a bit stumped on this problem. Before I jump into the issue, there's a couple of restrictions:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;I'm working in an environment that is running an old version of Splunk which &lt;U&gt;does not&lt;/U&gt; have access to the mvmap() function. Working on getting that updated, but until then I still need to try to get a solution to this problem figured out.&lt;/LI&gt;&lt;LI&gt;This operation is not the only piece of logic I'm trying to accomplish here. Assume there are other unnamed fields which are already in a specifically sorted way which we do not want to disturb.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm attempting to filter out all elements of a list which match the first element, leaving only the elements which are not a match. Here is an example which does work:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval base = split("A75CD,A75AB,A75CD,A75BA,A75DE",",")
| eval mv_to_search=mvindex(base,1,mvcount(base)-1)
| eval search_value=mvindex(base,0)

| eval COMMENT = "ABOVE IS ALL SETUP, BELOW IS ATTEMPTED SOLUTIONS"

| eval filtered_mv=mvfilter(!match(base, "A75CD"))
| eval var_type = typeof(search_value)
| table base, mv_to_search, search_value, filtered_mv, var_type&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, when I attempt to switch it out for something like the following, it does not work:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval base = split("A75CD,A75AB,A75CD,A75BA,A75DE",",")
| eval mv_to_search=mvindex(base,1,mvcount(base)-1)
| eval search_value=mvindex(base,0)

| eval COMMENT = "ABOVE IS ALL SETUP, BELOW IS ATTEMPTED SOLUTIONS"

| eval filtered_mv=mvfilter(!match(base, mvindex(base,0)))
| eval var_type = typeof(search_value)
| table base, mv_to_search, search_value, filtered_mv, var_type&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have even attempted to solve it using a foreach command, but was also unsuccessful:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval base = split("A75CD,A75AB,A75CD,A75BA,A75DE",",")
| eval mv_to_search=mvindex(base,1,mvcount(base)-1)
| eval search_value=mvindex(base,0)

| eval COMMENT = "ABOVE IS ALL SETUP, BELOW IS ATTEMPTED SOLUTIONS"

| foreach mode=multivalue base [eval filtered_mv = if('&amp;lt;&amp;lt;ITEM&amp;gt;&amp;gt;'!=mvindex(base,0), mvappend(filtered_mv,'&amp;lt;&amp;lt;ITEM&amp;gt;&amp;gt;'), filtered_mv)]
| eval var_type = typeof(search_value)
| table base, mv_to_search, search_value, filtered_mv, var_type&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm open to any other ideas which might accomplish this better or more efficiently. Not sure where I'm going wrong with this one, or whether this idea is even possible.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Dec 2024 21:35:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Filter-out-all-elements-of-a-list-which-match-the-first-element/m-p/707648#M239329</guid>
      <dc:creator>BG_Splunk</dc:creator>
      <dc:date>2024-12-27T21:35:55Z</dc:date>
    </item>
    <item>
      <title>Re: Filter out all elements of a list which match the first element</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Filter-out-all-elements-of-a-list-which-match-the-first-element/m-p/707653#M239331</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/275171"&gt;@BG_Splunk&lt;/a&gt;&amp;nbsp;I you don't have mvmap, you won't have foreach mode=multivalue, but you can use foreach like this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| foreach 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 [ | eval e=mvindex(base, &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;), filtered_mv=mvappend(filtered_mv, if(!match(e, search_value), e, null())) ]
| eval var_type = typeof(search_value)
| table base, mv_to_search, search_value, filtered_mv, var_type&lt;/LI-CODE&gt;&lt;P&gt;where you just give incrementing numbers which are templated as &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; so you can mvindex using that.&lt;/P&gt;&lt;P&gt;mvfilter can't handle more than one field, so the mvindex(base, 0) won't work inside the filter expression.&lt;/P&gt;&lt;P&gt;I'm still using 7.3 in one environment so the above works in that and I used to use that technique before mvmap came along. It does require you to know the max size of the list in advance, but it doesn't have limits I have come up against.&lt;/P&gt;&lt;P&gt;It may also be possible to collapse the MV to a single value and then use some kind of rex/replace to get the matches out, but I've not tried that.&lt;/P&gt;</description>
      <pubDate>Sat, 28 Dec 2024 01:20:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Filter-out-all-elements-of-a-list-which-match-the-first-element/m-p/707653#M239331</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2024-12-28T01:20:44Z</dc:date>
    </item>
    <item>
      <title>Re: Filter out all elements of a list which match the first element</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Filter-out-all-elements-of-a-list-which-match-the-first-element/m-p/707654#M239332</link>
      <description>&lt;P&gt;If this is practical, you can do it with replace, i.e.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval elements = mvjoin(mv_to_search, "####")
| eval non_matches = replace(elements, search_value, ""), non_matches=split(non_matches, "####"), non_matches=mvfilter(isnotnull(non_matches)) &lt;/LI-CODE&gt;&lt;P&gt;which joins the elements with a known string, gets rid of all the matches, then splits again and removes nulls.&lt;/P&gt;</description>
      <pubDate>Sat, 28 Dec 2024 01:24:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Filter-out-all-elements-of-a-list-which-match-the-first-element/m-p/707654#M239332</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2024-12-28T01:24:57Z</dc:date>
    </item>
    <item>
      <title>Re: Filter out all elements of a list which match the first element</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Filter-out-all-elements-of-a-list-which-match-the-first-element/m-p/707655#M239333</link>
      <description>&lt;P&gt;My guy, that's a super smart solution! Thank you very much, I just tried this out and it works beautifully. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;I'm going to have to keep this kind of approach in mind as I go forward with this project. Very creative thinking!&lt;/P&gt;</description>
      <pubDate>Sat, 28 Dec 2024 01:37:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Filter-out-all-elements-of-a-list-which-match-the-first-element/m-p/707655#M239333</guid>
      <dc:creator>BG_Splunk</dc:creator>
      <dc:date>2024-12-28T01:37:13Z</dc:date>
    </item>
    <item>
      <title>Re: Filter out all elements of a list which match the first element</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Filter-out-all-elements-of-a-list-which-match-the-first-element/m-p/707656#M239334</link>
      <description>&lt;P&gt;That's a very smart way to do it! I'm going to need some time to dissect how that works, but I know off the bat that the biggest problem is going to be that the max size of the list is going to be variable each time this runs. Still, I think this is super clever and will keep this in mind. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 28 Dec 2024 01:39:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Filter-out-all-elements-of-a-list-which-match-the-first-element/m-p/707656#M239334</guid>
      <dc:creator>BG_Splunk</dc:creator>
      <dc:date>2024-12-28T01:39:00Z</dc:date>
    </item>
    <item>
      <title>Re: Filter out all elements of a list which match the first element</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Filter-out-all-elements-of-a-list-which-match-the-first-element/m-p/707674#M239343</link>
      <description>&lt;P&gt;If you always know what the upper max list size will be then you can put foreach numbers 0 1...999999 if you really needed as nothing will happen for those outside the actual size of the MV.&lt;/P&gt;&lt;P&gt;If you're doing this in a dashboard, you could technically create a token with the numbered steps and use the token in the foreach, e.g.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| foreach $steps_to_iterate$&lt;/LI-CODE&gt;&lt;P&gt;where steps to iterate is calculated in a post process search of the list and simply&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| stats max(eval(mvcount(list))) as max_list
| eval r=mvjoin(mvrange(1, max_list + 1, 1), " ")&lt;/LI-CODE&gt;&lt;P&gt;with this &amp;lt;done&amp;gt; clause in the dashboard search&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;done&amp;gt;
  &amp;lt;set token="steps_to_iterate"&amp;gt;$result.max_list$&amp;lt;/set&amp;gt;
&amp;lt;/done&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 28 Dec 2024 20:53:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Filter-out-all-elements-of-a-list-which-match-the-first-element/m-p/707674#M239343</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2024-12-28T20:53:13Z</dc:date>
    </item>
  </channel>
</rss>

