<?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: extracting fields between pattern in a search and and calculating length of value in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/extracting-fields-between-pattern-in-a-search-and-and/m-p/271749#M176316</link>
    <description>&lt;P&gt;Since its a case of searching between = and &amp;amp; did you try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;yourSearch
| rex "\=(?&amp;lt;valueOfField&amp;gt;[^\&amp;amp;]+)\&amp;amp;.*"
| eval length=len(valueOfField)
|eval numArgs = mvcount(split(valueOfField,","))
| table valueofField, length, numArgs
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 25 Oct 2016 15:14:12 GMT</pubDate>
    <dc:creator>gokadroid</dc:creator>
    <dc:date>2016-10-25T15:14:12Z</dc:date>
    <item>
      <title>extracting fields between pattern in a search and and calculating length of value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extracting-fields-between-pattern-in-a-search-and-and/m-p/271746#M176313</link>
      <description>&lt;P&gt;Hello. &lt;/P&gt;

&lt;P&gt;I have a simmilar quesiton to this : &lt;BR /&gt;
&lt;A href="https://answers.splunk.com/answers/176585/how-to-extract-a-field-between-two-patterns-in-a-s.html" target="_blank"&gt;https://answers.splunk.com/answers/176585/how-to-extract-a-field-between-two-patterns-in-a-s.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;I want to do something similar for Get Request strings with patterns similar to this  : &lt;/P&gt;

&lt;P&gt;GET  /~/rest/collection?ghostAccountPrompts=LP36,IL46,ID59&amp;amp;hyperlinkPrompts&lt;/P&gt;

&lt;P&gt;between ? AND =  is the field_Name . in the above the field_Name is ghostAccountPrompts&lt;/P&gt;

&lt;P&gt;I need to extract everything between   field_Name= and &amp;amp; pattern so i can do stats searches include calculate the length of the value of the field.  so in  the above  I need to calculate the length of value LP36,IL46,ID59  which in this example is 14. &lt;/P&gt;

&lt;P&gt;what I want to end up with is a table with Extracted field names with length and Count &lt;BR /&gt;
Field Name                            Length    Count &lt;BR /&gt;
ABC                                            20               3&lt;BR /&gt;
ABC                                            10               1&lt;BR /&gt;
DEF                                            10               4&lt;/P&gt;

&lt;P&gt;can you help ?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 11:32:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extracting-fields-between-pattern-in-a-search-and-and/m-p/271746#M176313</guid>
      <dc:creator>shere</dc:creator>
      <dc:date>2020-09-29T11:32:54Z</dc:date>
    </item>
    <item>
      <title>Re: extracting fields between pattern in a search and and calculating length of value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extracting-fields-between-pattern-in-a-search-and-and/m-p/271747#M176314</link>
      <description>&lt;P&gt;Is this what you are looking for?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex  "\?(?&amp;lt;key&amp;gt;[^=]+)=(?&amp;lt;value&amp;gt;[^&amp;amp;]+)&amp;amp;"
| eval {key} = value
| fields - key, value
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count | fields - count
| eval _raw ="GET /~/rest/collection?ghostAccountPrompts=LP36,IL46,ID59&amp;amp;hyperlinkPrompts"
| rex  "\?(?&amp;lt;key&amp;gt;[^=]+)=(?&amp;lt;value&amp;gt;[^&amp;amp;]+)&amp;amp;"
| eval {key} = value
| fields - key, value
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Output (see picture below):&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/2061i1CDDF3A7E69AEFB6/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Oct 2016 15:08:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extracting-fields-between-pattern-in-a-search-and-and/m-p/271747#M176314</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-10-25T15:08:43Z</dc:date>
    </item>
    <item>
      <title>Re: extracting fields between pattern in a search and and calculating length of value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extracting-fields-between-pattern-in-a-search-and-and/m-p/271748#M176315</link>
      <description>&lt;P&gt;This should get you started.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex "\?(?&amp;lt;Field&amp;gt;[^=]*)=(?&amp;lt;fieldValue&amp;gt;[^&amp;amp;]+)" | eval Length = len(fieldValue) | stats count as Count, values(Length) as Length by Field | table Field Length Count
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Oct 2016 15:11:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extracting-fields-between-pattern-in-a-search-and-and/m-p/271748#M176315</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2016-10-25T15:11:38Z</dc:date>
    </item>
    <item>
      <title>Re: extracting fields between pattern in a search and and calculating length of value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extracting-fields-between-pattern-in-a-search-and-and/m-p/271749#M176316</link>
      <description>&lt;P&gt;Since its a case of searching between = and &amp;amp; did you try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;yourSearch
| rex "\=(?&amp;lt;valueOfField&amp;gt;[^\&amp;amp;]+)\&amp;amp;.*"
| eval length=len(valueOfField)
|eval numArgs = mvcount(split(valueOfField,","))
| table valueofField, length, numArgs
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Oct 2016 15:14:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extracting-fields-between-pattern-in-a-search-and-and/m-p/271749#M176316</guid>
      <dc:creator>gokadroid</dc:creator>
      <dc:date>2016-10-25T15:14:12Z</dc:date>
    </item>
    <item>
      <title>Re: extracting fields between pattern in a search and and calculating length of value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extracting-fields-between-pattern-in-a-search-and-and/m-p/271750#M176317</link>
      <description>&lt;P&gt;Thanks for the prompt reply, this would of hit the nail on the head if it wasn't for something I missed. So for a single field in the get request this will work, but there is actually two fields...&lt;BR /&gt;
so need to now split the fields and achieve the same thing. So basically one get request string can contain one or more fields : &lt;/P&gt;

&lt;P&gt;GET /~/rest/collection?ghostAccountPrompts=IL46&amp;amp;hyperlinkPrompts=IL59,IL53,IC21 HTTP/1.1\r\nHost&lt;/P&gt;

&lt;P&gt;ghostAccountPrompts is one field - get the length of the value between Prompts=  and &amp;amp; &lt;BR /&gt;
hyperlinkPrompts is another field - get the length of the value between Prompts=  and HTTP&lt;/P&gt;

&lt;P&gt;Need to extract the fields and calculate length of values of the fields &lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;Need to search string GET /~/rest/collection? &lt;/LI&gt;
&lt;LI&gt;Extract the fields&lt;/LI&gt;
&lt;LI&gt;calculate the length of the field values&lt;/LI&gt;
&lt;LI&gt;put it in a table with each instance  for field and length &lt;/LI&gt;
&lt;LI&gt; if possible a count for each Field Name and number of times same length is matched&lt;BR /&gt;&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;Field Length  Count &lt;BR /&gt;
ABC  20           number of time ABC is length 20 &lt;BR /&gt;
ABC  10           number of time ABC is length 10&lt;BR /&gt;
DEF  10 &lt;/P&gt;</description>
      <pubDate>Tue, 25 Oct 2016 16:19:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extracting-fields-between-pattern-in-a-search-and-and/m-p/271750#M176317</guid>
      <dc:creator>shere</dc:creator>
      <dc:date>2016-10-25T16:19:59Z</dc:date>
    </item>
    <item>
      <title>Re: extracting fields between pattern in a search and and calculating length of value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extracting-fields-between-pattern-in-a-search-and-and/m-p/271751#M176318</link>
      <description>&lt;P&gt;Try this.  It will do the matching, but you'll have to play with the rest a bit to get the multi-value fields to expand right.  I don't have a lot of time to work on it today.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex max_match=0 "(?:\?|&amp;amp;)(?&amp;lt;Field&amp;gt;[^=]*)=(?&amp;lt;fieldValue&amp;gt;[^&amp;amp; ]+)" | mvexpand Field | eval Length = len(fieldValue) | stats count as Count, values(Length) as Length by Field | table Field Length Count
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Oct 2016 18:19:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extracting-fields-between-pattern-in-a-search-and-and/m-p/271751#M176318</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2016-10-25T18:19:17Z</dc:date>
    </item>
    <item>
      <title>Re: extracting fields between pattern in a search and and calculating length of value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extracting-fields-between-pattern-in-a-search-and-and/m-p/271752#M176319</link>
      <description>&lt;P&gt;All, both Rich and Gokadroid provided the solution &lt;/P&gt;

&lt;P&gt;Rich's search extracted the fields correctly and Gokadroid search calculated the value of the field correctly. I had to combine both answers to get what I wanted.  I could not get the multi value fields to be extracted and calculated in one search, so I split each search by the pattern.  I also used Rich's search to find all the multivalue fields , it did not correctly give me the values, but at least I identified them so I could do separate searches for them&lt;/P&gt;

&lt;P&gt;for ghostAccountPrompts I searched between = to &amp;amp;:&lt;BR /&gt;
mysearch | rex "\?(?[^=]&lt;EM&gt;)=(?[^&amp;amp;]+)&amp;amp;.&lt;/EM&gt;"&lt;BR /&gt;
   | eval length=len(valueOfField)&lt;BR /&gt;
 |eval numArgs = mvcount(split(valueOfField,","))&lt;BR /&gt;
 | table Field, valueofField, length, numArgs&lt;/P&gt;

&lt;P&gt;for hyperlinkPrompts I searchd between = to HTTP:&lt;/P&gt;

&lt;P&gt;mysearch | rex "\?(?[^=]&lt;EM&gt;)=(?[^=]+)\HTTP.&lt;/EM&gt;"&lt;BR /&gt;
   | eval length=len(valueOfField)&lt;BR /&gt;
 |eval numArgs = mvcount(split(valueOfField,","))&lt;BR /&gt;
 | table Field, length, numArgs&lt;/P&gt;

&lt;P&gt;thanks for all your help. Secondly if someone now can see the missing piece of the puzzle to expand the multi-value fields in one search then it will be useful learning exercise for me and am keen to try it. &lt;/P&gt;</description>
      <pubDate>Mon, 31 Oct 2016 12:24:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extracting-fields-between-pattern-in-a-search-and-and/m-p/271752#M176319</guid>
      <dc:creator>shere</dc:creator>
      <dc:date>2016-10-31T12:24:37Z</dc:date>
    </item>
  </channel>
</rss>

