<?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 extract multiple key value pairs from the logs in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-multiple-key-value-pairs-from-the-logs/m-p/383728#M112073</link>
    <description>&lt;P&gt;The values in the parenthesis are still within a field called "message". the events looks like below &lt;/P&gt;

&lt;P&gt;First event: value=null , message = 100 the message is (123=456.56;45=Yes;......), key=value &lt;BR /&gt;
Second event: value=null, message= 101 the message is (123=12; 45=No; ...) , key1=value1 &lt;BR /&gt;
Third event: value=1, message = 102 the message is (abc=wxy.yx;123=456.56,45=no;.....)&lt;BR /&gt;
Fourth event: value=2, message= 103 the message is (45=Yes;...) , key2=value2&lt;/P&gt;

&lt;P&gt;I need the values in the paranthesis in a field, so that I can look for the different values of 123, 45 , abc in the logs with the help of a query. &lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Thu, 02 Aug 2018 20:16:04 GMT</pubDate>
    <dc:creator>knr26</dc:creator>
    <dc:date>2018-08-02T20:16:04Z</dc:date>
    <item>
      <title>How to extract multiple key value pairs from the logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-multiple-key-value-pairs-from-the-logs/m-p/383722#M112067</link>
      <description>&lt;P&gt;We have a requirement where we need to extract the multiple key value pairs from the log files &lt;/P&gt;

&lt;P&gt;Ex:  places= multiple, values = They are (city=ABC;location=PNX.AZ;45678=0879), extraction=true&lt;/P&gt;

&lt;P&gt;I am trying to extract the values enclosed in brackets which are seperated by ";". The output I am looking for is &lt;/P&gt;

&lt;P&gt;a) city as the filed and value as ABC &lt;BR /&gt;
b)location as field name and PNX.AZ  as its value &lt;BR /&gt;
c) 45678 as field name and 0879 as its value   ( I read that splunk field name cannot start with a number - If this is so, is there any possibility that we can add a value before it, eg: A45678 as field name ) &lt;/P&gt;

&lt;P&gt;There are many events in the same format and all the values for the field city should go in "city" field. &lt;/P&gt;

&lt;P&gt;I am so unsure if this has to be done by a regex or if I can use a split command to extract the values.  User is looking for a search where he can query by City to find list of all the cities and similarly stats count by location should give all the locations&lt;/P&gt;

&lt;P&gt;Thanks for your help &lt;/P&gt;</description>
      <pubDate>Thu, 02 Aug 2018 18:02:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-multiple-key-value-pairs-from-the-logs/m-p/383722#M112067</guid>
      <dc:creator>knr26</dc:creator>
      <dc:date>2018-08-02T18:02:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract multiple key value pairs from the logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-multiple-key-value-pairs-from-the-logs/m-p/383723#M112068</link>
      <description>&lt;P&gt;Hello there, &lt;/P&gt;

&lt;P&gt;Assuming below statements are always true, give this a shot. &lt;CODE&gt;your_search | rex field=_raw "\(city\=(?&amp;lt;city&amp;gt;\w+)\;location\=(?&amp;lt;location&amp;gt;\w+\.\w+)\;\d+\=(?&amp;lt;A456789&amp;gt;\d+)"&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;a) city field will always start with &lt;CODE&gt;city=&lt;/CODE&gt;&lt;BR /&gt;
b)location field will always start with &lt;CODE&gt;location=&lt;/CODE&gt; and the value is always &lt;CODE&gt;city.state&lt;/CODE&gt; (For ex. SFO.CA, NYC.NY)&lt;BR /&gt;&lt;BR /&gt;
c) 45678 field will always start with &lt;CODE&gt;numbers=&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Tested here: &lt;A href="https://regex101.com/r/qRmhFi/2"&gt;https://regex101.com/r/qRmhFi/2&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;If it works, then your final search query will look something like &lt;CODE&gt;your_search | rex field=_raw "\(city\=(?&amp;lt;city&amp;gt;\w+)\;location\=(?&amp;lt;location&amp;gt;\w+\.\w+)\;\d+\=(?&amp;lt;A456789&amp;gt;\d+)" | stats count by location&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Aug 2018 18:35:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-multiple-key-value-pairs-from-the-logs/m-p/383723#M112068</guid>
      <dc:creator>sudosplunk</dc:creator>
      <dc:date>2018-08-02T18:35:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract multiple key value pairs from the logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-multiple-key-value-pairs-from-the-logs/m-p/383724#M112069</link>
      <description>&lt;P&gt;Thanks for your response surya. Those are just examples, we do have a bunch of Key value pairs within the brackets. Most of them are digits and they are not consistent or in the order. &lt;/P&gt;

&lt;P&gt;Eg: If the first event has only three key value pairs, second have more than 20 and the third has 10. &lt;/P&gt;

&lt;P&gt;Do we need to write regex to match all of these seperately? Please note that they are not in the order too &lt;/P&gt;</description>
      <pubDate>Thu, 02 Aug 2018 19:38:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-multiple-key-value-pairs-from-the-logs/m-p/383724#M112069</guid>
      <dc:creator>knr26</dc:creator>
      <dc:date>2018-08-02T19:38:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract multiple key value pairs from the logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-multiple-key-value-pairs-from-the-logs/m-p/383725#M112070</link>
      <description>&lt;P&gt;Are those values within parenthesis extracted in a field?&lt;/P&gt;</description>
      <pubDate>Thu, 02 Aug 2018 19:46:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-multiple-key-value-pairs-from-the-logs/m-p/383725#M112070</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-08-02T19:46:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract multiple key value pairs from the logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-multiple-key-value-pairs-from-the-logs/m-p/383726#M112071</link>
      <description>&lt;P&gt;In that case, can you provide sample data and highlight the fields which are supposed to be extracted. Please mask unwanted information. Thank you.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Aug 2018 19:52:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-multiple-key-value-pairs-from-the-logs/m-p/383726#M112071</guid>
      <dc:creator>sudosplunk</dc:creator>
      <dc:date>2018-08-02T19:52:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract multiple key value pairs from the logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-multiple-key-value-pairs-from-the-logs/m-p/383727#M112072</link>
      <description>&lt;P&gt;No, they are not. The values in the parenthesis are still within a field along with a string message before the paranthesis &lt;/P&gt;

&lt;P&gt;In the first event : value= null, Message= 100 the message is (123=456.78; 45=Yes; .......) &lt;BR /&gt;
In the second event : value= null, Message = 101 the message is ( 123=678 ; 45=No ; .....) &lt;BR /&gt;
Third event :  value=null, Message = 102 the message is (Abc=wbc; 123=456.78 ; 21=56; 45=No ; ....) &lt;BR /&gt;
Fouth event:  value=null, Message =103 the message is (45=No;......) , value1=zero &lt;/P&gt;

&lt;P&gt;The values in the parenthisis are still within a field called "Message"&lt;/P&gt;</description>
      <pubDate>Thu, 02 Aug 2018 20:06:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-multiple-key-value-pairs-from-the-logs/m-p/383727#M112072</guid>
      <dc:creator>knr26</dc:creator>
      <dc:date>2018-08-02T20:06:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract multiple key value pairs from the logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-multiple-key-value-pairs-from-the-logs/m-p/383728#M112073</link>
      <description>&lt;P&gt;The values in the parenthesis are still within a field called "message". the events looks like below &lt;/P&gt;

&lt;P&gt;First event: value=null , message = 100 the message is (123=456.56;45=Yes;......), key=value &lt;BR /&gt;
Second event: value=null, message= 101 the message is (123=12; 45=No; ...) , key1=value1 &lt;BR /&gt;
Third event: value=1, message = 102 the message is (abc=wxy.yx;123=456.56,45=no;.....)&lt;BR /&gt;
Fourth event: value=2, message= 103 the message is (45=Yes;...) , key2=value2&lt;/P&gt;

&lt;P&gt;I need the values in the paranthesis in a field, so that I can look for the different values of 123, 45 , abc in the logs with the help of a query. &lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 02 Aug 2018 20:16:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-multiple-key-value-pairs-from-the-logs/m-p/383728#M112073</guid>
      <dc:creator>knr26</dc:creator>
      <dc:date>2018-08-02T20:16:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract multiple key value pairs from the logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-multiple-key-value-pairs-from-the-logs/m-p/383729#M112074</link>
      <description>&lt;P&gt;Give this a try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search 
| extract pairdelim=";" mv_add=t
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Aug 2018 20:36:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-multiple-key-value-pairs-from-the-logs/m-p/383729#M112074</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-08-02T20:36:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract multiple key value pairs from the logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-multiple-key-value-pairs-from-the-logs/m-p/383730#M112075</link>
      <description>&lt;P&gt;Thanks for your response. But, this did not work. The values are not extracted &lt;/P&gt;</description>
      <pubDate>Thu, 02 Aug 2018 21:24:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-multiple-key-value-pairs-from-the-logs/m-p/383730#M112075</guid>
      <dc:creator>knr26</dc:creator>
      <dc:date>2018-08-02T21:24:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract multiple key value pairs from the logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-multiple-key-value-pairs-from-the-logs/m-p/383731#M112076</link>
      <description>&lt;P&gt;See this (everything before extract is to generate sample data)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1 | eval raw="value= null, Message= 100 the message is (123=456.78; 45=Yes; .......)#value= null, Message = 101 the message is ( 123=678 ; 45=No ; .....) #value=null, Message = 102 the message is (Abc=wbc; 123=456.78 ; 21=56; 45=No ; ....) #value=null, Message =103 the message is (45=No;......) , value1=zero" | table raw | makemv raw delim="#" | mvexpand raw | rename raw as _raw 
| extract pairdelim=";" kvdelim="=" clean_keys=f
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Aug 2018 21:39:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-multiple-key-value-pairs-from-the-logs/m-p/383731#M112076</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-08-02T21:39:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract multiple key value pairs from the logs</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-multiple-key-value-pairs-from-the-logs/m-p/383732#M112077</link>
      <description>&lt;P&gt;Thank you so much. This worked &lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2018 17:47:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-multiple-key-value-pairs-from-the-logs/m-p/383732#M112077</guid>
      <dc:creator>knr26</dc:creator>
      <dc:date>2018-08-07T17:47:09Z</dc:date>
    </item>
  </channel>
</rss>

