<?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 Count values in multivalue field encoded as a string in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Count-values-in-multivalue-field-encoded-as-a-string/m-p/413081#M119106</link>
    <description>&lt;P&gt;I have the following entry in several of my events:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;puppy_name = "Scout Windixie Spot"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If it's not obvious already, this field, puppy_name, has 3 different values. It really should be:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;puppy_names = ["Scout", "Windixie", "Spot"]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That said, I have a couple of questions: &lt;BR /&gt;
&lt;EM&gt;Note&lt;/EM&gt; if you can help me with question 2, then don't bother with 1&lt;BR /&gt;
1) What spl query can I construct to count the number of unique strings in &lt;CODE&gt;puppy_name&lt;/CODE&gt; and put the result in a new field called &lt;CODE&gt;puppy_name_count&lt;/CODE&gt;?&lt;BR /&gt;
I have already tried:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="puppies" | eval puppy_name_count=mvcount(split(puppy_name, " "))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Assuming &lt;CODE&gt;split()&lt;/CODE&gt; returns an array (although I can't say this for sure because I couldn't find any documentation on &lt;CODE&gt;split()&lt;/CODE&gt;), I need something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="puppies" | eval puppy_name_count=array_length(split(puppy_name, " "))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Does anyone know how I can achieve this?&lt;/P&gt;

&lt;P&gt;2) Is there an spl query or splunk configuration I can write to automatically split in the different puppy names in puppy_name into something like: &lt;CODE&gt;puppys_name=["Scout", "Windixie", "Spot"]&lt;/CODE&gt;?&lt;/P&gt;</description>
    <pubDate>Wed, 30 Sep 2020 01:30:07 GMT</pubDate>
    <dc:creator>brinley</dc:creator>
    <dc:date>2020-09-30T01:30:07Z</dc:date>
    <item>
      <title>Count values in multivalue field encoded as a string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-values-in-multivalue-field-encoded-as-a-string/m-p/413081#M119106</link>
      <description>&lt;P&gt;I have the following entry in several of my events:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;puppy_name = "Scout Windixie Spot"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If it's not obvious already, this field, puppy_name, has 3 different values. It really should be:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;puppy_names = ["Scout", "Windixie", "Spot"]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That said, I have a couple of questions: &lt;BR /&gt;
&lt;EM&gt;Note&lt;/EM&gt; if you can help me with question 2, then don't bother with 1&lt;BR /&gt;
1) What spl query can I construct to count the number of unique strings in &lt;CODE&gt;puppy_name&lt;/CODE&gt; and put the result in a new field called &lt;CODE&gt;puppy_name_count&lt;/CODE&gt;?&lt;BR /&gt;
I have already tried:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="puppies" | eval puppy_name_count=mvcount(split(puppy_name, " "))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Assuming &lt;CODE&gt;split()&lt;/CODE&gt; returns an array (although I can't say this for sure because I couldn't find any documentation on &lt;CODE&gt;split()&lt;/CODE&gt;), I need something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="puppies" | eval puppy_name_count=array_length(split(puppy_name, " "))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Does anyone know how I can achieve this?&lt;/P&gt;

&lt;P&gt;2) Is there an spl query or splunk configuration I can write to automatically split in the different puppy names in puppy_name into something like: &lt;CODE&gt;puppys_name=["Scout", "Windixie", "Spot"]&lt;/CODE&gt;?&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 01:30:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-values-in-multivalue-field-encoded-as-a-string/m-p/413081#M119106</guid>
      <dc:creator>brinley</dc:creator>
      <dc:date>2020-09-30T01:30:07Z</dc:date>
    </item>
    <item>
      <title>Re: Count values in multivalue field encoded as a string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-values-in-multivalue-field-encoded-as-a-string/m-p/413082#M119107</link>
      <description>&lt;P&gt;This does work. So if that isn't working in your data then you have some hidden character. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval puppy_name = "Scout Windixie Spot" 
| eval nameCount=mvcount(split(puppy_name," "))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Play around with field extraction to break them up similar to &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval puppy_name = "Scout Windixie Spot" 
| rex field=puppy_name max_match=0 "(?P&amp;lt;puppy_names&amp;gt;[^\s\r\n]+)" 
| eval nameCount=mvcount(split(puppy_names," "))
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Jul 2019 19:52:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-values-in-multivalue-field-encoded-as-a-string/m-p/413082#M119107</guid>
      <dc:creator>starcher</dc:creator>
      <dc:date>2019-07-24T19:52:23Z</dc:date>
    </item>
    <item>
      <title>Re: Count values in multivalue field encoded as a string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-values-in-multivalue-field-encoded-as-a-string/m-p/413083#M119108</link>
      <description>&lt;P&gt;Hi @brinley&lt;/P&gt;

&lt;P&gt;Check this&lt;/P&gt;

&lt;P&gt;To find the number of unique strings:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    | makeresults 
    | eval puppy_name = "Scout Windixie Spot Scout" 
    | makemv delim=" " puppy_name 
    | eval puppy_name_count =mvcount(mvdedup(puppy_name)) 
    | table puppy_name_count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;String in the required format:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval puppy_name = "Scout Windixie Spot Scout" 
| makemv delim=" " puppy_name 
| eval puppy_name =mvdedup(puppy_name) 
| mvexpand puppy_name 
| eval puppy_name = "\"".puppy_name."\"" 
| mvcombine puppy_name delim="," 
| nomv puppy_name 
| eval puppy_name = "[".puppy_name."]" 
| table puppy_name
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Jul 2019 03:42:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-values-in-multivalue-field-encoded-as-a-string/m-p/413083#M119108</guid>
      <dc:creator>vnravikumar</dc:creator>
      <dc:date>2019-07-25T03:42:56Z</dc:date>
    </item>
    <item>
      <title>Re: Count values in multivalue field encoded as a string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Count-values-in-multivalue-field-encoded-as-a-string/m-p/413084#M119109</link>
      <description>&lt;P&gt;1) &lt;BR /&gt;
| makeresults&lt;BR /&gt;
| eval puppy_name = "Scout Windixie Spot Spot"  &lt;/P&gt;

&lt;H2&gt;|  eval name_count = mvcount(mvdedup(split(puppy_name," ")))&lt;/H2&gt;

&lt;P&gt;2) it looks like a list in python,  I'm not sure splunk has a function that converts a list string directly into a multi-valued field, I recommend parsing it first with a regular expression, like this:&lt;BR /&gt;
| makeresults &lt;BR /&gt;
| eval puppy_name ="['Scout', 'Windixie', 'Spot','Spot']" &lt;BR /&gt;
| rex field=puppy_name  "'(?P[^']+)'" max_match=0 &lt;BR /&gt;
| eval name_count = mvcount(mvdedup(name))&lt;/P&gt;

&lt;P&gt;Hope that helps&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 01:30:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Count-values-in-multivalue-field-encoded-as-a-string/m-p/413084#M119109</guid>
      <dc:creator>zillionlee</dc:creator>
      <dc:date>2020-09-30T01:30:24Z</dc:date>
    </item>
  </channel>
</rss>

