<?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 split a multivalue field into single values? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-split-a-multivalue-field-into-single-values/m-p/201629#M58413</link>
    <description>&lt;P&gt;@richgalloway&lt;/P&gt;

&lt;P&gt;Thank you for your response - quick follow up question - can I extract all three of the values to the SINGLE new field - perhaps similar to the below;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex field=foo "(?&amp;lt;ip_new&amp;gt;[^\s]+)\s(?&amp;lt;ip_new&amp;gt;[^,]+),\s(?&amp;lt;ip_new&amp;gt;.*)" | ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Also - not sure if you have the time, but care to explain the logic behind your REGEX code?&lt;/P&gt;</description>
    <pubDate>Mon, 19 Dec 2016 00:02:25 GMT</pubDate>
    <dc:creator>alexandermunce</dc:creator>
    <dc:date>2016-12-19T00:02:25Z</dc:date>
    <item>
      <title>How to split a multivalue field into single values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-split-a-multivalue-field-into-single-values/m-p/201627#M58411</link>
      <description>&lt;P&gt;I am working with a field &lt;STRONG&gt;&amp;lt; source_ip &amp;gt;&lt;/STRONG&gt; containing three IP addresses and am wanting to split the values of that field into individual values.&lt;/P&gt;

&lt;P&gt;The field data currently looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;10.1.0.1 192.168.0.1, 192.168.2.1
10.1.0.1 192.168.3.1, 192.168.4.2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;As you can see, the first and second IP addresses are separated by a &lt;STRONG&gt;space&lt;/STRONG&gt; and the second and third is separated by &lt;CODE&gt;,&lt;/CODE&gt; (a comma and a space).&lt;/P&gt;

&lt;P&gt;I have tried using SPL commands to split this data, but I feel that a command which uses REGEX may be more suitable.&lt;/P&gt;

&lt;P&gt;Is it possible to split these IP addresses into individual values in the same field, ie the &lt;STRONG&gt;&amp;lt; source_ip &amp;gt;&lt;/STRONG&gt; field will then contain a list of single IP addresses (rather than splitting the three values into three separate fields).&lt;/P&gt;</description>
      <pubDate>Sun, 18 Dec 2016 23:15:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-split-a-multivalue-field-into-single-values/m-p/201627#M58411</guid>
      <dc:creator>alexandermunce</dc:creator>
      <dc:date>2016-12-18T23:15:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a multivalue field into single values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-split-a-multivalue-field-into-single-values/m-p/201628#M58412</link>
      <description>&lt;P&gt;If the field always contains exactly three IP addresses then this &lt;CODE&gt;rex&lt;/CODE&gt; command should do the job.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex field=foo "(?&amp;lt;ip1&amp;gt;[^\s]+)\s(?&amp;lt;ip2&amp;gt;[^,]+),\s(?&amp;lt;ip3&amp;gt;.*)" | ...
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 18 Dec 2016 23:56:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-split-a-multivalue-field-into-single-values/m-p/201628#M58412</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2016-12-18T23:56:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a multivalue field into single values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-split-a-multivalue-field-into-single-values/m-p/201629#M58413</link>
      <description>&lt;P&gt;@richgalloway&lt;/P&gt;

&lt;P&gt;Thank you for your response - quick follow up question - can I extract all three of the values to the SINGLE new field - perhaps similar to the below;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex field=foo "(?&amp;lt;ip_new&amp;gt;[^\s]+)\s(?&amp;lt;ip_new&amp;gt;[^,]+),\s(?&amp;lt;ip_new&amp;gt;.*)" | ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Also - not sure if you have the time, but care to explain the logic behind your REGEX code?&lt;/P&gt;</description>
      <pubDate>Mon, 19 Dec 2016 00:02:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-split-a-multivalue-field-into-single-values/m-p/201629#M58413</guid>
      <dc:creator>alexandermunce</dc:creator>
      <dc:date>2016-12-19T00:02:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a multivalue field into single values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-split-a-multivalue-field-into-single-values/m-p/201630#M58414</link>
      <description>&lt;P&gt;@richgalloway &lt;/P&gt;

&lt;P&gt;One other question - I feel that it may likely be the case that only the 2nd or 3rd IP address may be relevant in the end - can I tweak your REGEX code so that it ignore the first and/or second IP and only extracts the third?&lt;/P&gt;</description>
      <pubDate>Mon, 19 Dec 2016 00:06:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-split-a-multivalue-field-into-single-values/m-p/201630#M58414</guid>
      <dc:creator>alexandermunce</dc:creator>
      <dc:date>2016-12-19T00:06:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a multivalue field into single values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-split-a-multivalue-field-into-single-values/m-p/201631#M58415</link>
      <description>&lt;P&gt;Regular expressions don't allow the same group name to be used more than once so your &lt;CODE&gt;rex&lt;/CODE&gt; command won't work.&lt;/P&gt;

&lt;P&gt;To split the field into a new (multi-valued) field, use the &lt;CODE&gt;split&lt;/CODE&gt; function.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval bar=split(replace(foo, ",", "")," ") | ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The &lt;CODE&gt;replace&lt;/CODE&gt; function removes the comma.  The result is a multi-valued field containing the three IP addresses.  You can use mv commands to access them.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Dec 2016 00:11:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-split-a-multivalue-field-into-single-values/m-p/201631#M58415</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2016-12-19T00:11:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a multivalue field into single values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-split-a-multivalue-field-into-single-values/m-p/201632#M58416</link>
      <description>&lt;P&gt;Extract just the third IP address with this regex&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex field=foo ", (?&amp;lt;ip&amp;gt;.*)" | ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You also requested an explanation of my original regex.&lt;BR /&gt;
&lt;CODE&gt;(?&amp;lt;ip1&amp;gt;[^\s]+)&lt;/CODE&gt; takes everything up to the first white space and puts it into field 'ip1'&lt;BR /&gt;
&lt;CODE&gt;\s(?&amp;lt;ip2&amp;gt;[^,]+)&lt;/CODE&gt; skips a space then puts everything up to the next comma into field 'ip2'&lt;BR /&gt;
&lt;CODE&gt;,\s(?&amp;lt;ip3&amp;gt;.*)&lt;/CODE&gt; skips a comma and a space and puts the remaining characters into field 'ip3'.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Dec 2016 00:19:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-split-a-multivalue-field-into-single-values/m-p/201632#M58416</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2016-12-19T00:19:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a multivalue field into single values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-split-a-multivalue-field-into-single-values/m-p/201633#M58417</link>
      <description>&lt;P&gt;You are a gentleman and a scholar, thank you kindly!&lt;/P&gt;

&lt;P&gt;Answer accepted and upvoted.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Dec 2016 00:23:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-split-a-multivalue-field-into-single-values/m-p/201633#M58417</guid>
      <dc:creator>alexandermunce</dc:creator>
      <dc:date>2016-12-19T00:23:23Z</dc:date>
    </item>
  </channel>
</rss>

