<?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: Create key value pairs from existing fields in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Create-key-value-pairs-from-existing-fields/m-p/191298#M55079</link>
    <description>&lt;P&gt;The challenge is that for string1 and string 2, there are random number of values, although they will have the same number of them.&lt;/P&gt;

&lt;P&gt;There are 3 in the first event and then 2 in the next.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;2014-10-23 22:25:41 string1=key1|key2|key3  string2=value1|value2|value3
2014-10-23 22:26:00 string1=key4|key5  string2=value4|value5
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 03 Nov 2014 03:08:46 GMT</pubDate>
    <dc:creator>ben_leung</dc:creator>
    <dc:date>2014-11-03T03:08:46Z</dc:date>
    <item>
      <title>Create key value pairs from existing fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Create-key-value-pairs-from-existing-fields/m-p/191294#M55075</link>
      <description>&lt;P&gt;In _raw:&lt;/P&gt;

&lt;P&gt;string1=key1|key2|key3|key4|key5|key6 string2=value1|value2|value3|value4|value5|value6&lt;/P&gt;

&lt;P&gt;I want to manipulate/rearrange and get an output that is like this.&lt;/P&gt;

&lt;P&gt;key1=value1&lt;BR /&gt;
key2=value2&lt;BR /&gt;
key3=value3&lt;BR /&gt;
...&lt;/P&gt;</description>
      <pubDate>Sat, 01 Nov 2014 01:15:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Create-key-value-pairs-from-existing-fields/m-p/191294#M55075</guid>
      <dc:creator>ben_leung</dc:creator>
      <dc:date>2014-11-01T01:15:24Z</dc:date>
    </item>
    <item>
      <title>Re: Create key value pairs from existing fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Create-key-value-pairs-from-existing-fields/m-p/191295#M55076</link>
      <description>&lt;P&gt;May be this...&lt;/P&gt;

&lt;P&gt;base search| makemv delim="|" System1|makemv delim="|" System2|eval fields = mvzip(System1,System2)|mvexpand fields|rex field=fields "(?\w+|\d+),(?\w+|\d+)"|eval New_Field = alpha + "=" + beta|table alpha,beta,New_Field&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 18:03:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Create-key-value-pairs-from-existing-fields/m-p/191295#M55076</guid>
      <dc:creator>Raghav2384</dc:creator>
      <dc:date>2020-09-28T18:03:53Z</dc:date>
    </item>
    <item>
      <title>Re: Create key value pairs from existing fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Create-key-value-pairs-from-existing-fields/m-p/191296#M55077</link>
      <description>&lt;P&gt;Hi, this should get you in the right direction:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...|rex field=_raw "string1=(?&amp;lt;field1&amp;gt;\w+\d+)\|(?&amp;lt;field3&amp;gt;\w+\d+)\|(?&amp;lt;field5&amp;gt;\w+\d+)\|(?&amp;lt;field7&amp;gt;\w+\d+)\|(?&amp;lt;field9&amp;gt;\w+\d+)\|(?&amp;lt;field11&amp;gt;\w+\d+)\sstring2=(?&amp;lt;field2&amp;gt;\w+\d+)\|(?&amp;lt;field4&amp;gt;\w+\d+)\|(?&amp;lt;field6&amp;gt;\w+\d+)\|(?&amp;lt;field8&amp;gt;\w+\d+)\|(?&amp;lt;field10&amp;gt;\w+\d+)\|(?&amp;lt;field12&amp;gt;\w+\d+)$" | eval _raw=field1."=".field2.",".field3."=".field4.",".field5."=".field6.",".field7."=".field8.",".field9."=".field10.",".field11."=".field12
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 01 Nov 2014 06:03:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Create-key-value-pairs-from-existing-fields/m-p/191296#M55077</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2014-11-01T06:03:53Z</dc:date>
    </item>
    <item>
      <title>Re: Create key value pairs from existing fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Create-key-value-pairs-from-existing-fields/m-p/191297#M55078</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;base search| makemv delim="|" System1|makemv delim="|" System2|eval fields = mvzip(System1,System2)|mvexpand fields
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The new "fields" field has what I need but only gets the first fields="key1=vlaue1". The other fields and values are not grabbed since the mvzip argument in the eval command only grabs the first.&lt;/P&gt;

&lt;P&gt;Not sure what is the purpose for the rex command and everything after that.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Nov 2014 03:03:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Create-key-value-pairs-from-existing-fields/m-p/191297#M55078</guid>
      <dc:creator>ben_leung</dc:creator>
      <dc:date>2014-11-03T03:03:21Z</dc:date>
    </item>
    <item>
      <title>Re: Create key value pairs from existing fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Create-key-value-pairs-from-existing-fields/m-p/191298#M55079</link>
      <description>&lt;P&gt;The challenge is that for string1 and string 2, there are random number of values, although they will have the same number of them.&lt;/P&gt;

&lt;P&gt;There are 3 in the first event and then 2 in the next.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;2014-10-23 22:25:41 string1=key1|key2|key3  string2=value1|value2|value3
2014-10-23 22:26:00 string1=key4|key5  string2=value4|value5
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 03 Nov 2014 03:08:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Create-key-value-pairs-from-existing-fields/m-p/191298#M55079</guid>
      <dc:creator>ben_leung</dc:creator>
      <dc:date>2014-11-03T03:08:46Z</dc:date>
    </item>
    <item>
      <title>Re: Create key value pairs from existing fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Create-key-value-pairs-from-existing-fields/m-p/191299#M55080</link>
      <description>&lt;P&gt;Dude... what is up with this data!&lt;/P&gt;

&lt;P&gt;This is probably easier another way, but this example supports up to 10 key values and rewrites the timestamp as well, note i separate the date from the other strings with a colon in the eval, you might want to change it to a space. Finally we remove the extra ,= if they exist using sed:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...|rex field=_raw "(^.*(?=string1=))string1=(?&amp;lt;f1&amp;gt;\w+)?\|?(?&amp;lt;f2&amp;gt;\w+)?\|?(?&amp;lt;f3&amp;gt;\w+)?\|?(?&amp;lt;f4&amp;gt;\w+)?\|?(?&amp;lt;f5&amp;gt;\w+)?\|?(?&amp;lt;f6&amp;gt;\w+)?\|?(?&amp;lt;f7&amp;gt;\w+)?\|?(?&amp;lt;f8&amp;gt;\w+)?\|?(?&amp;lt;f9&amp;gt;\w+)?\|?(?&amp;lt;f10&amp;gt;\w+)?\|?\s+string2=(?&amp;lt;f11&amp;gt;\w+)?\|?(?&amp;lt;f12&amp;gt;\w+)?\|?(?&amp;lt;f13&amp;gt;\w+)?\|?(?&amp;lt;f14&amp;gt;\w+)?\|?(?&amp;lt;f15&amp;gt;\w+)?\|?(?&amp;lt;f16&amp;gt;\w+)?\|?(?&amp;lt;f17&amp;gt;\w+)?\|?(?&amp;lt;f18&amp;gt;\w+)?\|?(?&amp;lt;f19&amp;gt;\w+)?\|?(?&amp;lt;f20&amp;gt;\w+)?\|?$" | eval _raw=f1.":".f2.=".f12.",".f3."=".f13.",".f4."=".f14.",".f5."=".f15.",".f6."=".f16.",".f7."=".f17.",".f8."=".f18.",".f9."=".f19.",".f10."=".f20.",".f11."=".f21 | rex mode=sed field=_raw "s/(\,=)+//g"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Works in theory!&lt;/P&gt;</description>
      <pubDate>Fri, 07 Nov 2014 03:43:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Create-key-value-pairs-from-existing-fields/m-p/191299#M55080</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2014-11-07T03:43:03Z</dc:date>
    </item>
    <item>
      <title>Re: Create key value pairs from existing fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Create-key-value-pairs-from-existing-fields/m-p/191300#M55081</link>
      <description>&lt;P&gt;The office politics with developers..&lt;/P&gt;</description>
      <pubDate>Fri, 07 Nov 2014 05:00:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Create-key-value-pairs-from-existing-fields/m-p/191300#M55081</guid>
      <dc:creator>ben_leung</dc:creator>
      <dc:date>2014-11-07T05:00:07Z</dc:date>
    </item>
    <item>
      <title>Re: Create key value pairs from existing fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Create-key-value-pairs-from-existing-fields/m-p/191301#M55082</link>
      <description>&lt;P&gt;does the crazy expensive search above work for now?  Are you ok with the commas between the key value pairs or did you absolutely need line breaks?&lt;/P&gt;</description>
      <pubDate>Fri, 07 Nov 2014 16:36:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Create-key-value-pairs-from-existing-fields/m-p/191301#M55082</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2014-11-07T16:36:45Z</dc:date>
    </item>
    <item>
      <title>Re: Create key value pairs from existing fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Create-key-value-pairs-from-existing-fields/m-p/191302#M55083</link>
      <description>&lt;P&gt;If this is your _raw data &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;2014-10-23 22:25:41 string1=key1|key2|key3  string2=value1|value2|value3
 2014-10-23 22:26:00 string1=key4|key5  string2=value4|value5
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;then try this (runanywhere sample, till eval _time=now() is just for generating dummy data, this will be your base search)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1 | eval temp="2014-10-23 22:25:41 string1=key1|key2|key3  string2=value1|value2|value3#2014-10-23 22:26:00 string1=key4|key5  string2=value4|value5" | table temp | makemv temp delim="#" | mvexpand temp | rename temp as _raw| extract pairdelim=" ", kvdelim="=:" | eval _time=now()
| eval string1="timestamp|".string1 | eval string2=_time."|".string2 | makemv delim="|" string1 | makemv delim="|" string2 | eval temp=mvzip(string1,string2,"=") | nomv temp | rename temp as _raw | table _raw| extract pairdelim=" ", kvdelim="=:"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Nov 2014 17:31:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Create-key-value-pairs-from-existing-fields/m-p/191302#M55083</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2014-11-07T17:31:16Z</dc:date>
    </item>
  </channel>
</rss>

