<?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: Return index position of {someValue} in multi-value field in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Return-index-position-of-someValue-in-multi-value-field/m-p/60784#M14943</link>
    <description>&lt;P&gt;Think that rawKeys have "aaa,bbb,ccc".&lt;/P&gt;

&lt;P&gt;the solution:
...
| eval keys=split(rawKeys,",")
| eval countKeys=mvcount(keys)
| mvexpand keys
| map search=" search | head 1 
| eval key=\"$keys$\" 
| eval rawKeys=\"$rawKeys$,\" 
| eval countKeys=\"$countKeys$\" 
| rex field=rawKeys \"$keys$(?.*)\" 
| eval positionKey=(countKeys-(mvcount(split(endBlock,\",\"))-1) )  " ...&lt;/P&gt;

&lt;P&gt;in the end result "aaa" positionKey = 0, "bbb" positionKey = 1 and "ccc" positionKey = 2. &lt;/P&gt;</description>
    <pubDate>Fri, 04 Mar 2011 01:13:52 GMT</pubDate>
    <dc:creator>ildo</dc:creator>
    <dc:date>2011-03-04T01:13:52Z</dc:date>
    <item>
      <title>Return index position of {someValue} in multi-value field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Return-index-position-of-someValue-in-multi-value-field/m-p/60782#M14941</link>
      <description>&lt;P&gt;I'm using transaction to combine events &amp;amp; generate multi-value fields. What I want to do is keep the values of a mv field after the first occurance of some value.&lt;/P&gt;

&lt;P&gt;My first guess was to use a command that returned the index position of the value within the mv field, then use mvindex to get what I wanted. Only problem, I don't see a command that let's me search of mvfield and get the location of "value".&lt;/P&gt;

&lt;P&gt;Am I missing something? If not, anyone have a workaround?&lt;/P&gt;

&lt;P&gt;Just to clarify, if I have the following mv field called Names:
john
bob
fred
don&lt;/P&gt;

&lt;P&gt;I want to get rid of all values before the 1st occurance of bob. End result would be:
bob
fred
don&lt;/P&gt;

&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Thu, 30 Sep 2010 05:52:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Return-index-position-of-someValue-in-multi-value-field/m-p/60782#M14941</guid>
      <dc:creator>stjack99</dc:creator>
      <dc:date>2010-09-30T05:52:04Z</dc:date>
    </item>
    <item>
      <title>Re: Return index position of {someValue} in multi-value field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Return-index-position-of-someValue-in-multi-value-field/m-p/60783#M14942</link>
      <description>&lt;P&gt;One workaround:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host=xxx | search Names="bob" | eval DelimitedNames=mvjoin(Names,";") | rex mode=sed field=DelimitedNames "s/^(.*?;)*bob/bob/" | eval InterestingNames=split(DelimitedNames,";")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Flatten the multi-value field into a text string, then use &lt;CODE&gt;rex&lt;/CODE&gt; to strip out everything before "&lt;CODE&gt;bob&lt;/CODE&gt;", and then expand the result back into a multi-value field.&lt;/P&gt;

&lt;P&gt;Remove &lt;CODE&gt;search Names="bob"&lt;/CODE&gt; if you want to preserve all values when bob is not seen at all.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Sep 2010 06:25:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Return-index-position-of-someValue-in-multi-value-field/m-p/60783#M14942</guid>
      <dc:creator>southeringtonp</dc:creator>
      <dc:date>2010-09-30T06:25:23Z</dc:date>
    </item>
    <item>
      <title>Re: Return index position of {someValue} in multi-value field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Return-index-position-of-someValue-in-multi-value-field/m-p/60784#M14943</link>
      <description>&lt;P&gt;Think that rawKeys have "aaa,bbb,ccc".&lt;/P&gt;

&lt;P&gt;the solution:
...
| eval keys=split(rawKeys,",")
| eval countKeys=mvcount(keys)
| mvexpand keys
| map search=" search | head 1 
| eval key=\"$keys$\" 
| eval rawKeys=\"$rawKeys$,\" 
| eval countKeys=\"$countKeys$\" 
| rex field=rawKeys \"$keys$(?.*)\" 
| eval positionKey=(countKeys-(mvcount(split(endBlock,\",\"))-1) )  " ...&lt;/P&gt;

&lt;P&gt;in the end result "aaa" positionKey = 0, "bbb" positionKey = 1 and "ccc" positionKey = 2. &lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2011 01:13:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Return-index-position-of-someValue-in-multi-value-field/m-p/60784#M14943</guid>
      <dc:creator>ildo</dc:creator>
      <dc:date>2011-03-04T01:13:52Z</dc:date>
    </item>
    <item>
      <title>Re: Return index position of {someValue} in multi-value field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Return-index-position-of-someValue-in-multi-value-field/m-p/512140#M143626</link>
      <description>&lt;P&gt;I don't know which version it was introduced in, but mvrange and mvzip can be used.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;...
| eval keys = split(rawKeys, ",")
| eval index_and_key = mvzip(mvrange(0, mvcount(keys)), keys, ",")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Aug 2020 12:49:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Return-index-position-of-someValue-in-multi-value-field/m-p/512140#M143626</guid>
      <dc:creator>malvidin</dc:creator>
      <dc:date>2020-08-03T12:49:45Z</dc:date>
    </item>
  </channel>
</rss>

