<?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: position of a string in another string in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/position-of-a-string-in-another-string/m-p/26130#M5020</link>
    <description>&lt;P&gt;Thanks echalex,&lt;/P&gt;

&lt;P&gt;I have been trying to get it to work, but not really coming right. It could possibly be due to a transaction.&lt;/P&gt;

&lt;P&gt;Given I have logs:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;date - sessionId: xyz, uri: "/"
date - sessionId: xyz, uri: "/login"
date - sessionId: xyz, uri: "/signup"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;with the dates increasing, when I add to a transaction, it merges all the entries. So with an mvindex on a split, it should split on the "/login" string, and mvindex 0 should return "date - .... "/".... uri:" but I am not getting it as expected... &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;someSearch | transaction SessionID | eval n=mvindex(split(uri,"/login"),0)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 10 Aug 2012 11:35:31 GMT</pubDate>
    <dc:creator>brettcave</dc:creator>
    <dc:date>2012-08-10T11:35:31Z</dc:date>
    <item>
      <title>position of a string in another string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/position-of-a-string-in-another-string/m-p/26128#M5018</link>
      <description>&lt;P&gt;I was looking through the functions available for locating the position of 1 string in another string, and couldn't see one (in &lt;A href="http://docs.splunk.com/Documentation/Splunk/4.3.3/SearchReference/CommonEvalFunctions"&gt;http://docs.splunk.com/Documentation/Splunk/4.3.3/SearchReference/CommonEvalFunctions&lt;/A&gt;). &lt;/P&gt;

&lt;P&gt;While mvindex and substr will return the element at a position in a string or mv item, mvfind is meant to return the index of an element in an mv field.&lt;/P&gt;

&lt;P&gt;However, is there no function to get the position of a string within another string (e.g. php's strpos function). "match" returns a boolean on matching a string, but if a function that worked the same as match, but returned a numeric value for the number of matches would give a lot more scope to eval.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval n=match_count("search","[ae]")
// n = 2. 0 means no matches
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Aug 2012 11:45:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/position-of-a-string-in-another-string/m-p/26128#M5018</guid>
      <dc:creator>brettcave</dc:creator>
      <dc:date>2012-08-06T11:45:27Z</dc:date>
    </item>
    <item>
      <title>Re: position of a string in another string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/position-of-a-string-in-another-string/m-p/26129#M5019</link>
      <description>&lt;P&gt;Hi brettcave,&lt;BR /&gt;
You could split the field into a mv-field and take the length of the first value of the mv-field:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval foo=mvindex(split(your_field, "your string"),0) |eval bar=if(foo!=your_field,len(foo),-1)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The second eval will give &lt;CODE&gt;foo&lt;/CODE&gt; the value -1 if "your string" isn't in &lt;CODE&gt;your_field&lt;/CODE&gt;. Otherwise, it's the index. (To be exact, the number of characters before "your string". Change -1 to whatever you like.&lt;/P&gt;

&lt;P&gt;HTH&lt;/P&gt;</description>
      <pubDate>Mon, 06 Aug 2012 13:38:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/position-of-a-string-in-another-string/m-p/26129#M5019</guid>
      <dc:creator>echalex</dc:creator>
      <dc:date>2012-08-06T13:38:08Z</dc:date>
    </item>
    <item>
      <title>Re: position of a string in another string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/position-of-a-string-in-another-string/m-p/26130#M5020</link>
      <description>&lt;P&gt;Thanks echalex,&lt;/P&gt;

&lt;P&gt;I have been trying to get it to work, but not really coming right. It could possibly be due to a transaction.&lt;/P&gt;

&lt;P&gt;Given I have logs:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;date - sessionId: xyz, uri: "/"
date - sessionId: xyz, uri: "/login"
date - sessionId: xyz, uri: "/signup"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;with the dates increasing, when I add to a transaction, it merges all the entries. So with an mvindex on a split, it should split on the "/login" string, and mvindex 0 should return "date - .... "/".... uri:" but I am not getting it as expected... &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;someSearch | transaction SessionID | eval n=mvindex(split(uri,"/login"),0)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 10 Aug 2012 11:35:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/position-of-a-string-in-another-string/m-p/26130#M5020</guid>
      <dc:creator>brettcave</dc:creator>
      <dc:date>2012-08-10T11:35:31Z</dc:date>
    </item>
    <item>
      <title>Re: position of a string in another string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/position-of-a-string-in-another-string/m-p/26131#M5021</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;... | transaction mvlist=t SessionID | ....
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;mvlist=t - order based on natural order (sequence of events).&lt;BR /&gt;
mvlist=f - lexigraphical ordering (default)&lt;/P&gt;</description>
      <pubDate>Fri, 24 Aug 2012 09:29:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/position-of-a-string-in-another-string/m-p/26131#M5021</guid>
      <dc:creator>brettcave</dc:creator>
      <dc:date>2012-08-24T09:29:57Z</dc:date>
    </item>
  </channel>
</rss>

