<?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: Combining separate fields to multi values in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Combining-separate-fields-to-multi-values/m-p/231454#M68660</link>
    <description>&lt;P&gt;Not sure if this will work, but if the data is consistent maybe you can use rex to along with some mv commands&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count | eval blah="match_1=\"Don\'t Be So Shy\" match_2=\"Imany\" match_3=\"8,980,580\" match_4=\"Human\" match_5=\"Rag\'n\'Bone Man\" match_6=\"763,862\" match_7=\"Closer\" match_8=\" Chainsmokers\" match_9=\"3,671,646\"" 
| rex field=blah "match\_\d+=(?&amp;lt;title&amp;gt;\"[^\"]+\")\s+match\_\d+=(?&amp;lt;name&amp;gt;\"[^\"]+\")\s+match\_\d+=(?&amp;lt;score&amp;gt;\"[^\"]+\")" max_match=0 
| eval temp = mvzip(title,name) 
| eval temp = mvzip(temp,score) 
| fields temp 
| mvexpand temp 
| rex field=temp "^(?&amp;lt;title&amp;gt;[^,]+),(?&amp;lt;name&amp;gt;[^,]+),(?&amp;lt;score&amp;gt;.+)" 
| fields - temp 
| table title name score
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 06 Oct 2016 00:23:59 GMT</pubDate>
    <dc:creator>maciep</dc:creator>
    <dc:date>2016-10-06T00:23:59Z</dc:date>
    <item>
      <title>Combining separate fields to multi values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combining-separate-fields-to-multi-values/m-p/231446#M68652</link>
      <description>&lt;P&gt;I have 300 match_ fields per event. Here are the first 9 from one event:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;match_1="Don\'t Be So Shy" match_2="Imany" match_3="8,980,580" match_4="Human" match_5="Rag\'n\'Bone Man" match_6="763,862" match_7="Closer" match_8=" Chainsmokers" match_9="3,671,646"...etc
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I want to structure the result so I'll get triplets of data as:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;title="Don\'t Be So Shy" name="Imany" score="8,980,580" 
title="Human" name="Rag\'n\'Bone Man" score="763,862" 
title="Closer" name="Chainsmokers" score="8,980,580"...etc
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I am messing around with modulus and mv functions  in order to first connect the 3 relating fields and then expand to simulate the triplets as each their event, but with no succes. &lt;/P&gt;

&lt;P&gt;Any help would be much appreciated.  &lt;/P&gt;</description>
      <pubDate>Wed, 05 Oct 2016 15:05:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combining-separate-fields-to-multi-values/m-p/231446#M68652</guid>
      <dc:creator>thdose</dc:creator>
      <dc:date>2016-10-05T15:05:04Z</dc:date>
    </item>
    <item>
      <title>Re: Combining separate fields to multi values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combining-separate-fields-to-multi-values/m-p/231447#M68653</link>
      <description>&lt;P&gt;Give this a try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search | table match_* | eval temp=1 | untable temp fieldname fieldvalue 
| eval rank=floor((tonumber(mvindex(split(fieldname,"_"),1))+1)/3) | streamstats count as label by rank |
eval label=case(label=1,"title", label=2,"name",true(),"score") | chart values(fieldvalue) over rank by label
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Update&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search | table match_* | eval temp=1 | accum temp| untable temp fieldname fieldvalue 
| eval rank=floor((tonumber(mvindex(split(fieldname,"_"),1))+1)/3) | eval rank=temp."-".rank | streamstats count as label by rank | eval label=case(label=1,"title", label=2,"name",true(),"score") | chart values(fieldvalue) over rank by label | fields - rank
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Oct 2016 16:36:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combining-separate-fields-to-multi-values/m-p/231447#M68653</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-10-05T16:36:18Z</dc:date>
    </item>
    <item>
      <title>Re: Combining separate fields to multi values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combining-separate-fields-to-multi-values/m-p/231448#M68654</link>
      <description>&lt;P&gt;Thanks. Almost, but not quite. It seems some values get mixed up: &lt;/P&gt;

&lt;P&gt;&lt;IMG src="http://i.imgur.com/mXABaWr.png" alt="alt text" /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Oct 2016 16:54:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combining-separate-fields-to-multi-values/m-p/231448#M68654</guid>
      <dc:creator>thdose</dc:creator>
      <dc:date>2016-10-05T16:54:32Z</dc:date>
    </item>
    <item>
      <title>Re: Combining separate fields to multi values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combining-separate-fields-to-multi-values/m-p/231449#M68655</link>
      <description>&lt;P&gt;Try the updated answer.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Oct 2016 17:05:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combining-separate-fields-to-multi-values/m-p/231449#M68655</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-10-05T17:05:38Z</dc:date>
    </item>
    <item>
      <title>Re: Combining separate fields to multi values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combining-separate-fields-to-multi-values/m-p/231450#M68656</link>
      <description>&lt;P&gt;&lt;IMG src="http://i.imgur.com/jpl0dFK.png" alt="alt text" /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Oct 2016 17:15:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combining-separate-fields-to-multi-values/m-p/231450#M68656</guid>
      <dc:creator>thdose</dc:creator>
      <dc:date>2016-10-05T17:15:02Z</dc:date>
    </item>
    <item>
      <title>Re: Combining separate fields to multi values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combining-separate-fields-to-multi-values/m-p/231451#M68657</link>
      <description>&lt;P&gt;Seems like there are some null values for some of the fields due to which the order of assignment is failing. Can you confirm if that is the case (try to run everything before the last chart command in the search and see the result).&lt;/P&gt;</description>
      <pubDate>Wed, 05 Oct 2016 18:22:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combining-separate-fields-to-multi-values/m-p/231451#M68657</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-10-05T18:22:40Z</dc:date>
    </item>
    <item>
      <title>Re: Combining separate fields to multi values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combining-separate-fields-to-multi-values/m-p/231452#M68658</link>
      <description>&lt;P&gt;If can't seem to find any null values. Here are the first fields in the first event:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;raw_match_count="300" match_1="Don\'t Be So Shy (Filatov &amp;amp; Karas Remix)" match_2="Imany" match_3="8,980,580" match_4="Human" match_5="Rag\'n\'Bone Man" match_6="763,862" match_7="Closer" match_8="The Chainsmokers Feat. Halsey" match_9="3,671,646" match_10="Dancing On My Own" match_11="Calum Scott" match_12="678,533" match_13="Starboy" match_14="The Weeknd Feat. Daft Punk" match_15="802,807" match_16="Still Falling For You" match_17="Ellie Goulding" match_18="581,123" match_19="The Greatest" match_20="Sia Feat. Kendrick Lamar" match_21="926,971" match_22="Sexual" match_23="NEIKED" match_24="108,857" match_25="Starving" match_26="Hailee Steinfeld &amp;amp; Grey Feat. Zedd" match_27="758,657" match_28="Heathens" match_29="Twenty One Pilots" match_30="3,066,742"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Oct 2016 18:49:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combining-separate-fields-to-multi-values/m-p/231452#M68658</guid>
      <dc:creator>thdose</dc:creator>
      <dc:date>2016-10-05T18:49:27Z</dc:date>
    </item>
    <item>
      <title>Re: Combining separate fields to multi values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combining-separate-fields-to-multi-values/m-p/231453#M68659</link>
      <description>&lt;P&gt;Can you provide a screenshot of following query? need to see first few lines as they are the one which are not working.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search | table match_* | eval temp=1 | accum temp| untable temp fieldname fieldvalue  | eval rank=floor((tonumber(mvindex(split(fieldname,"_"),1))+1)/3) | eval rank=temp."-".rank | streamstats count as label by rank | eval label=case(label=1,"title", label=2,"name",true(),"score")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Oct 2016 21:19:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combining-separate-fields-to-multi-values/m-p/231453#M68659</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-10-05T21:19:18Z</dc:date>
    </item>
    <item>
      <title>Re: Combining separate fields to multi values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combining-separate-fields-to-multi-values/m-p/231454#M68660</link>
      <description>&lt;P&gt;Not sure if this will work, but if the data is consistent maybe you can use rex to along with some mv commands&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count | eval blah="match_1=\"Don\'t Be So Shy\" match_2=\"Imany\" match_3=\"8,980,580\" match_4=\"Human\" match_5=\"Rag\'n\'Bone Man\" match_6=\"763,862\" match_7=\"Closer\" match_8=\" Chainsmokers\" match_9=\"3,671,646\"" 
| rex field=blah "match\_\d+=(?&amp;lt;title&amp;gt;\"[^\"]+\")\s+match\_\d+=(?&amp;lt;name&amp;gt;\"[^\"]+\")\s+match\_\d+=(?&amp;lt;score&amp;gt;\"[^\"]+\")" max_match=0 
| eval temp = mvzip(title,name) 
| eval temp = mvzip(temp,score) 
| fields temp 
| mvexpand temp 
| rex field=temp "^(?&amp;lt;title&amp;gt;[^,]+),(?&amp;lt;name&amp;gt;[^,]+),(?&amp;lt;score&amp;gt;.+)" 
| fields - temp 
| table title name score
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Oct 2016 00:23:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combining-separate-fields-to-multi-values/m-p/231454#M68660</guid>
      <dc:creator>maciep</dc:creator>
      <dc:date>2016-10-06T00:23:59Z</dc:date>
    </item>
    <item>
      <title>Re: Combining separate fields to multi values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combining-separate-fields-to-multi-values/m-p/231455#M68661</link>
      <description>&lt;P&gt;Sure:&lt;/P&gt;

&lt;P&gt;&lt;IMG src="http://i.imgur.com/rdKjCLh.png" alt="alt text" /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Oct 2016 11:07:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combining-separate-fields-to-multi-values/m-p/231455#M68661</guid>
      <dc:creator>thdose</dc:creator>
      <dc:date>2016-10-06T11:07:41Z</dc:date>
    </item>
    <item>
      <title>Re: Combining separate fields to multi values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Combining-separate-fields-to-multi-values/m-p/231456#M68662</link>
      <description>&lt;P&gt;The problem is that...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval rank=floor((tonumber(mvindex(split(fieldname,"_"),1))+1)/3)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;...needs to be...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval rank=floor((tonumber(mvindex(split(fieldname,"_"),1))+2)/3)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;...and it works just fine.&lt;/P&gt;

&lt;P&gt;Run anywhere demonstration code - &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=100 
| streamstats count as recno 
| eval recgroup = ceiling((1+recno)/10) 
| eval recgroup="A".if(len(recgroup)=1,"00","0").recgroup
| eval suffix=case(len(recno)=3,recno,len(recno)=2,"0".recno,true(),"00".recno) 
| eval name="name".suffix,song="song".suffix,score=8000000+recno
| eval stuff=mvappend(song,name,score)
| table stuff recgroup
| stats list(stuff) as stuff by recgroup
| mvexpand stuff
| streamstats count as recno
| eval suffix=case(len(recno)=3,recno,len(recno)=2,"0".recno,true(),"00".recno) 
| eval fieldname="match_".recno
| eval {fieldname} = stuff
| stats values(match*) as match*
| rename COMMENT as "The above just generates test data"

| rename COMMENT as "and we try somesoni2's last solution, with +1 changed to +2"
| untable recno fieldname fieldvalue 
| eval rank=floor((tonumber(mvindex(split(fieldname,"_"),1))+2)/3) 
| streamstats count as label by rank 
| eval label=case(label=1,"title", label=2,"name",true(),"score") 
| chart values(fieldvalue) over rank by label
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;... generating ...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rank   name          score        title
1         name001   8000001   song001  
2         name002   8000002   song002  
3         name003   8000003   song003  
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;... etc&lt;/P&gt;</description>
      <pubDate>Wed, 17 May 2017 19:09:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Combining-separate-fields-to-multi-values/m-p/231456#M68662</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-05-17T19:09:20Z</dc:date>
    </item>
  </channel>
</rss>

