<?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 write multiple fields into one column as values? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-multiple-fields-into-one-column-as-values/m-p/268289#M80703</link>
    <description>&lt;P&gt;Nice.  Way more elegant than mine.&lt;/P&gt;</description>
    <pubDate>Thu, 02 Feb 2017 21:28:53 GMT</pubDate>
    <dc:creator>DalJeanis</dc:creator>
    <dc:date>2017-02-02T21:28:53Z</dc:date>
    <item>
      <title>How to write multiple fields into one column as values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-multiple-fields-into-one-column-as-values/m-p/268285#M80699</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I have a data that looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;----------

*ID1       field1=value1&amp;amp;field2=value2&amp;amp;field3=value3*

----------

*ID2       field1=value1&amp;amp;field3=value3&amp;amp;field4=value4&amp;amp;field7=value7*

----------
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The fields are extracted separately. However, I would like to summerize them all in one field and list them in a table according to ID. The result should look like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| ID  | field  | value  |
| ID1 | field1 | value1 |
| ID1 | field2 | value2 |
| ID1 | field3 | value3 |
| ID2 | field1 | value1 |
| ID2 | field3 | value3 |
| ID2 | field4 | value4 |
| ID2 | field7 | value7 |
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The field names are variable both in their names and count per ID. I tried unsuccessfully to extract a mv-field.&lt;/P&gt;

&lt;P&gt;Is there a way to do this?&lt;/P&gt;

&lt;P&gt;Best regards &lt;BR /&gt;
Sascha&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2017 14:35:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-multiple-fields-into-one-column-as-values/m-p/268285#M80699</guid>
      <dc:creator>snetuschil</dc:creator>
      <dc:date>2017-02-02T14:35:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to write multiple fields into one column as values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-multiple-fields-into-one-column-as-values/m-p/268286#M80700</link>
      <description>&lt;P&gt;1) How do you identify the ID field value?    is it everything before the first space, or what?&lt;/P&gt;

&lt;P&gt;2) do the fields have spaces in them, or have they been properly masked? For instance, if field1 had the value george has a cat" and field2 had the value 2500, would it say &lt;/P&gt;

&lt;P&gt;field1="George has a cat"&amp;amp;field2=2500&lt;/P&gt;

&lt;P&gt;or would it say&lt;/P&gt;

&lt;P&gt;field1=George%20has%20a%20cat%20&amp;amp;field2=2500&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2017 20:54:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-multiple-fields-into-one-column-as-values/m-p/268286#M80700</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-02-02T20:54:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to write multiple fields into one column as values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-multiple-fields-into-one-column-as-values/m-p/268287#M80701</link>
      <description>&lt;P&gt;try something like this, &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search .. | rex "(?&amp;lt;id&amp;gt;\w+)\s(?&amp;lt;fields&amp;gt;.*)" | eval temp=split(fields,"&amp;amp;") | mvexpand temp | rex field=temp "(?&amp;lt;field&amp;gt;.*)=(?&amp;lt;value&amp;gt;.*)" | table id, field, value 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Sample&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|stats c | eval _raw="ID1 field1=value1&amp;amp;field2=value2&amp;amp;field3=value3" |append[|stats c | eval _raw="ID2 field1=value1&amp;amp;field2=value2&amp;amp;field3=value3&amp;amp;field4=value4"] | rex "(?&amp;lt;id&amp;gt;\w+)\s(?&amp;lt;fields&amp;gt;.*)" | eval temp=split(fields,"&amp;amp;") | mvexpand temp | rex field=temp "(?&amp;lt;field&amp;gt;.*)=(?&amp;lt;value&amp;gt;.*)" | table id, field, value
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;your raw event should like as per your question... post your sample events . &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;ID1 field1=value1&amp;amp;field2=value2&amp;amp;field3=value3
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope this helps you!!&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2017 21:25:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-multiple-fields-into-one-column-as-values/m-p/268287#M80701</guid>
      <dc:creator>vasanthmss</dc:creator>
      <dc:date>2017-02-02T21:25:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to write multiple fields into one column as values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-multiple-fields-into-one-column-as-values/m-p/268288#M80702</link>
      <description>&lt;P&gt;Here's the basic method - &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval myraw = "ID1 field1=value1&amp;amp;field2=value2&amp;amp; field3=value3"
| append [| makeresults | eval myraw = "ID2 field1=value1&amp;amp;field3=value3&amp;amp;field4=value4&amp;amp;field7=value7"]
| append [| makeresults | eval myraw = "ID3 field1=George%20has%20a%20cat%20&amp;amp;field2=2500"]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The above code just generates test data.  this processes it to produce the table - &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=myraw "^(?&amp;lt;ID&amp;gt;\w+)\s"
| rex field=myraw max_match=10 "[\s|&amp;amp;](?P&amp;lt;fieldname&amp;gt;[^=]*)=(?P&amp;lt;fieldvalue&amp;gt;[^&amp;amp;]*)"
| eval fieldpair=mvzip(fieldname,fieldvalue,"!!!!")
| table ID fieldpair
| mvexpand fieldpair
| rex  field=fieldpair "(?&amp;lt;fieldname&amp;gt;.*)!!!!(?&amp;lt;fieldvalue&amp;gt;.*)"
| table ID fieldname fieldvalue
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Feb 2017 21:27:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-multiple-fields-into-one-column-as-values/m-p/268288#M80702</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-02-02T21:27:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to write multiple fields into one column as values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-multiple-fields-into-one-column-as-values/m-p/268289#M80703</link>
      <description>&lt;P&gt;Nice.  Way more elegant than mine.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2017 21:28:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-multiple-fields-into-one-column-as-values/m-p/268289#M80703</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-02-02T21:28:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to write multiple fields into one column as values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-multiple-fields-into-one-column-as-values/m-p/268290#M80704</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;this works very well on my data, thank you very much! The dummy data I posted was simplified, which is why I get some clutter in the transformed table. The real data looks like this:&lt;/P&gt;

&lt;P&gt;6388700277  27  attribution 1486110252126   anb_3=-1&amp;amp;uids=6331855527&amp;amp;anb_2=xpv&amp;amp;anb_1=-1&amp;amp;anb_0=-1&amp;amp;promo_3=-1&amp;amp;promo_2=-1&amp;amp;promo_1=-1&amp;amp;promo_0=-1&amp;amp;entrysourceID_3=-1&amp;amp;entrysourceID_2=-1&amp;amp;entrysourceID_1=-1&amp;amp;entrysourceID_0=-1&amp;amp;akt_3=-1&amp;amp;akt_2=-1&amp;amp;akt_1=-1&amp;amp;akt_0=-1&amp;amp;wid_3=6388700277&amp;amp;version_3=-1&amp;amp;wid_2=6385404791&amp;amp;version_2=-1&amp;amp;wid_1=6379987259&amp;amp;version_1=-1&amp;amp;wid_0=6375153270&amp;amp;version_0=-1&lt;/P&gt;

&lt;P&gt;Your extraction works fine for all fields but the first field where it should only read "anb_3". The values "27" and "attribution" are fixed "1486110252126" is different for every ID: &lt;/P&gt;

&lt;P&gt;id  field   value&lt;BR /&gt;
6388700277  27  attribution 1486110252126   anb_3   -1&lt;BR /&gt;
6388700277  uids    6331855527&lt;BR /&gt;
6388700277  anb_2   xpv&lt;BR /&gt;
6388700277  anb_1   -1&lt;BR /&gt;
6388700277  anb_0   -1&lt;BR /&gt;
6388700277  promo_3 -1&lt;BR /&gt;
6388700277  promo_2 -1&lt;BR /&gt;
6388700277  promo_1 -1&lt;BR /&gt;
6388700277  promo_0 -1&lt;BR /&gt;
6388700277  entrysourceID_3 -1&lt;BR /&gt;
6388700277  entrysourceID_2 -1&lt;BR /&gt;
6388700277  entrysourceID_1 -1&lt;BR /&gt;
6388700277  entrysourceID_0 -1&lt;BR /&gt;
6388700277  akt_3   -1&lt;BR /&gt;
6388700277  akt_2   -1&lt;BR /&gt;
6388700277  akt_1   -1&lt;BR /&gt;
6388700277  akt_0   -1&lt;BR /&gt;
6388700277  wid_3   6388700277&lt;BR /&gt;
6388700277  version_3   -1&lt;BR /&gt;
6388700277  wid_2   6385404791&lt;BR /&gt;
6388700277  version_2   -1&lt;BR /&gt;
6388700277  wid_1   6379987259&lt;BR /&gt;
6388700277  version_1   -1&lt;BR /&gt;
6388700277  wid_0   6375153270&lt;BR /&gt;
6388700277  version_0   -1&lt;/P&gt;

&lt;P&gt;Best regards&lt;BR /&gt;
Sascha&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 12:43:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-multiple-fields-into-one-column-as-values/m-p/268290#M80704</guid>
      <dc:creator>snetuschil</dc:creator>
      <dc:date>2020-09-29T12:43:06Z</dc:date>
    </item>
  </channel>
</rss>

