<?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: Need to split string with variable number of fields in All Apps and Add-ons</title>
    <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Need-to-split-string-with-variable-number-of-fields/m-p/316342#M37891</link>
    <description>&lt;P&gt;@jagdeepgupta813, following is a run any where search based on the data provided. First two pipes here are to mock up provided data. Please try out and confirm if this is what you are looking for.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|  makeresults
|  eval _raw="details=[ A_10B_20N_30Z_40AB_50AU_60CA_70]^"
|  rex field=_raw "details=\[\s(?&amp;lt;details&amp;gt;[^\]]+)\]\^"
|  rex field=details "(?&amp;lt;field&amp;gt;[^_]+)?_(?&amp;lt;value&amp;gt;\d+)" max_match=0
|  eval details=mvzip(field,value)
|  table details
|  mvexpand details
|  eval details=split(details,",")
|  eval field=mvindex(details,0)
|  eval value=mvindex(details,1)
|  fields - details
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS: Since in the data example details is a key value pair i.e. "details=", if details field is available during search time you will also not need first &lt;CODE&gt;rex&lt;/CODE&gt; on your &lt;CODE&gt;_raw&lt;/CODE&gt; data. You would need to confirm this as this could boost search performance.&lt;/P&gt;</description>
    <pubDate>Sat, 02 Sep 2017 05:02:34 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2017-09-02T05:02:34Z</dc:date>
    <item>
      <title>Need to split string with variable number of fields</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Need-to-split-string-with-variable-number-of-fields/m-p/316340#M37889</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;

&lt;P&gt;I have a string like this  "details=[ A_0B_0N_0Z_0AB_0AU_0CA_0]^"&lt;BR /&gt;
I need to split the above string by '_'  where left side would be a field name and right would be a value. Final requirement is to display all the fileds which has value =10 .&lt;BR /&gt;
Note: The string might have one or many such field/value combination &lt;/P&gt;

&lt;P&gt;Thanks in Advance.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 15:36:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Need-to-split-string-with-variable-number-of-fields/m-p/316340#M37889</guid>
      <dc:creator>jagdeepgupta813</dc:creator>
      <dc:date>2020-09-29T15:36:17Z</dc:date>
    </item>
    <item>
      <title>Re: Need to split string with variable number of fields</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Need-to-split-string-with-variable-number-of-fields/m-p/316341#M37890</link>
      <description>&lt;P&gt;Do you mean that the fields/values in the example are - &lt;CODE&gt;A=0, B=0, N=0, Z=0&lt;/CODE&gt;, etc.?&lt;/P&gt;</description>
      <pubDate>Sat, 02 Sep 2017 02:33:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Need-to-split-string-with-variable-number-of-fields/m-p/316341#M37890</guid>
      <dc:creator>ddrillic</dc:creator>
      <dc:date>2017-09-02T02:33:19Z</dc:date>
    </item>
    <item>
      <title>Re: Need to split string with variable number of fields</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Need-to-split-string-with-variable-number-of-fields/m-p/316342#M37891</link>
      <description>&lt;P&gt;@jagdeepgupta813, following is a run any where search based on the data provided. First two pipes here are to mock up provided data. Please try out and confirm if this is what you are looking for.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|  makeresults
|  eval _raw="details=[ A_10B_20N_30Z_40AB_50AU_60CA_70]^"
|  rex field=_raw "details=\[\s(?&amp;lt;details&amp;gt;[^\]]+)\]\^"
|  rex field=details "(?&amp;lt;field&amp;gt;[^_]+)?_(?&amp;lt;value&amp;gt;\d+)" max_match=0
|  eval details=mvzip(field,value)
|  table details
|  mvexpand details
|  eval details=split(details,",")
|  eval field=mvindex(details,0)
|  eval value=mvindex(details,1)
|  fields - details
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS: Since in the data example details is a key value pair i.e. "details=", if details field is available during search time you will also not need first &lt;CODE&gt;rex&lt;/CODE&gt; on your &lt;CODE&gt;_raw&lt;/CODE&gt; data. You would need to confirm this as this could boost search performance.&lt;/P&gt;</description>
      <pubDate>Sat, 02 Sep 2017 05:02:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Need-to-split-string-with-variable-number-of-fields/m-p/316342#M37891</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-09-02T05:02:34Z</dc:date>
    </item>
    <item>
      <title>Re: Need to split string with variable number of fields</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Need-to-split-string-with-variable-number-of-fields/m-p/316343#M37892</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval _raw="details=[ A_0B_0N_0Z_0AB_0AU_0CA_0]^"

| rename COMMENT AS "Everything above generates sample event data; everything below is your solution"

| rex max_match=0 mode=sed "s/([^_]+)_(\d+)/\1=\2,/g"
| kv
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 03 Sep 2017 21:58:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Need-to-split-string-with-variable-number-of-fields/m-p/316343#M37892</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-09-03T21:58:28Z</dc:date>
    </item>
  </channel>
</rss>

