<?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 string into multiple fields using whitespace as delimiter in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-split-a-string-into-multiple-fields-using-whitespace-as/m-p/178927#M51487</link>
    <description>&lt;P&gt;If you can make some assumptions about the values in the Details field, the following regex string will parse it, at least using your sample data.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?P&amp;lt;field1&amp;gt;.*) (?P&amp;lt;field2&amp;gt;GAP|AGAP|UA) (?P&amp;lt;field3&amp;gt;\w+\.\w+)?\s*(?P&amp;lt;field4&amp;gt;.*$)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 26 Jun 2015 12:11:15 GMT</pubDate>
    <dc:creator>richgalloway</dc:creator>
    <dc:date>2015-06-26T12:11:15Z</dc:date>
    <item>
      <title>How to split a string into multiple fields using whitespace as delimiter</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-split-a-string-into-multiple-fields-using-whitespace-as/m-p/178921#M51481</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;
I have a field called "details" with the following value:&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;details&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;GAP 16 GAP PLI 31                               
MR 400 AGAP V41.81 PLI 31                               
MR 400 AGAP V39.80 PLI 31                               
MR 300 AGAP V89.96 PLI 31                               
MR 400 AGAP V89.95 Oos.                                 
MR 400 AGAP V89.95 PLI 31                               
MR 400 AGAP V89.95 PLI 31                               
MR 400 AGAP V40.80 Oos.                                 
MR 300 AGAP V87.91 PLI 31                               
MR 300 AGAP V87.91 PLI 31                               
Mobile 100 AGAP V64.60 PLI 31                               
GAP GAP PLI 31                              
Mobile 200 AGAP V51.43 PLI 31                               
MR 400 AGAP V40.80 PLI 31                               
Mobile 200 AGAP V52.43 PLI 31                               
Mobile 200 AGAP V51.43 PLI 31                               
TSC UA V01.3C PLI 31                                
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I'd like to split these values into several fields and regroup them so that the final result would look like this:&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/432iE88EF726FFDD86B4/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;I tried using &lt;CODE&gt;..| eval temp=split(details," ") | eval field1=mvindex(temp,0) | etc..&lt;/CODE&gt; but it looked dirty and wrong..&lt;/P&gt;

&lt;P&gt;Would a regular expression do the trick?&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jun 2015 09:06:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-split-a-string-into-multiple-fields-using-whitespace-as/m-p/178921#M51481</guid>
      <dc:creator>cedmarjls32</dc:creator>
      <dc:date>2015-06-26T09:06:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a string into multiple fields using whitespace as delimiter</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-split-a-string-into-multiple-fields-using-whitespace-as/m-p/178922#M51482</link>
      <description>&lt;P&gt;A regular expression cannot distinguish a value that contains two words separated by a space from two one-word values separated by a space.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jun 2015 09:23:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-split-a-string-into-multiple-fields-using-whitespace-as/m-p/178922#M51482</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2015-06-26T09:23:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a string into multiple fields using whitespace as delimiter</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-split-a-string-into-multiple-fields-using-whitespace-as/m-p/178923#M51483</link>
      <description>&lt;P&gt;So it means I'm stuck with the split / mvindex command then?&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jun 2015 09:56:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-split-a-string-into-multiple-fields-using-whitespace-as/m-p/178923#M51483</guid>
      <dc:creator>cedmarjls32</dc:creator>
      <dc:date>2015-06-26T09:56:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a string into multiple fields using whitespace as delimiter</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-split-a-string-into-multiple-fields-using-whitespace-as/m-p/178924#M51484</link>
      <description>&lt;P&gt;It means your data is ambiguous. Do you have a source with commas, tabs, etc. separating the values or quoted values to distinguish spaces within a value from spaces separating two values?&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jun 2015 10:01:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-split-a-string-into-multiple-fields-using-whitespace-as/m-p/178924#M51484</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2015-06-26T10:01:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a string into multiple fields using whitespace as delimiter</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-split-a-string-into-multiple-fields-using-whitespace-as/m-p/178925#M51485</link>
      <description>&lt;P&gt;These values comes from a csv file which is formatted as follows:&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/430i2C6C58C07C4F9DE1/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;This csv file is generated by a script running on a device, then is indexed by Splunk so there's no way for me to make any modification.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jun 2015 11:48:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-split-a-string-into-multiple-fields-using-whitespace-as/m-p/178925#M51485</guid>
      <dc:creator>cedmarjls32</dc:creator>
      <dc:date>2015-06-26T11:48:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a string into multiple fields using whitespace as delimiter</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-split-a-string-into-multiple-fields-using-whitespace-as/m-p/178926#M51486</link>
      <description>&lt;P&gt;Like martin_mueller already said, your data is ambiguous there is no way to create a catch all regex, also split wil not work correct I think (at least it will not deliver the data in the form that you want). The problem is mainly in rows 1, 12 and 17.&lt;BR /&gt;
Row 1: misses a field and there is no way to determine that because there is just one space between field 2 and 4. &lt;BR /&gt;
 - Split will probably have this problem to.&lt;BR /&gt;
Row 17: The layout of the first field is different than in all the other fields, all other fields are &amp;lt; word &amp;gt;&amp;lt; space &amp;gt;&amp;lt; digit &amp;gt; these two are just &amp;lt; word &amp;gt;&lt;BR /&gt;
 - Again split will probably also have this problem because these rows have "less fields" (based on the amount of spaces in the row).&lt;BR /&gt;
Row 12: Is a combination of the above two points, the layout of the first field is different and it is missing a field&lt;BR /&gt;
If the above problems are resolved by for example filling empty fields with a "-", making sure that the first field always has the same layout, OR by putting a field separator in the data life will be al lot easier... till that time the below regex will hit on most rows correct (it will also hit on row 1...)&lt;/P&gt;

&lt;P&gt;For rows 2-11 and 13-16:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?ms)^(?&amp;lt;field1&amp;gt;\w+\s\d+)\s(?&amp;lt;field2&amp;gt;[^\s]+)\s(?&amp;lt;field3&amp;gt;[^\s]+)\s(?&amp;lt;field4&amp;gt;.+?)$
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 Jun 2015 11:57:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-split-a-string-into-multiple-fields-using-whitespace-as/m-p/178926#M51486</guid>
      <dc:creator>aholzel</dc:creator>
      <dc:date>2015-06-26T11:57:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a string into multiple fields using whitespace as delimiter</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-split-a-string-into-multiple-fields-using-whitespace-as/m-p/178927#M51487</link>
      <description>&lt;P&gt;If you can make some assumptions about the values in the Details field, the following regex string will parse it, at least using your sample data.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?P&amp;lt;field1&amp;gt;.*) (?P&amp;lt;field2&amp;gt;GAP|AGAP|UA) (?P&amp;lt;field3&amp;gt;\w+\.\w+)?\s*(?P&amp;lt;field4&amp;gt;.*$)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 Jun 2015 12:11:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-split-a-string-into-multiple-fields-using-whitespace-as/m-p/178927#M51487</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2015-06-26T12:11:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a string into multiple fields using whitespace as delimiter</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-split-a-string-into-multiple-fields-using-whitespace-as/m-p/178928#M51488</link>
      <description>&lt;P&gt;While that may indeed be a CSV file, the data in question appears to be in one column with no separators between your individual values. You're in deep deep &lt;EM&gt;ahem&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jun 2015 13:04:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-split-a-string-into-multiple-fields-using-whitespace-as/m-p/178928#M51488</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2015-06-26T13:04:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a string into multiple fields using whitespace as delimiter</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-split-a-string-into-multiple-fields-using-whitespace-as/m-p/178929#M51489</link>
      <description>&lt;P&gt;Ok, just found the solution using richgalloways regex string with split/mvindex commands&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  ..  | rex field=details "(?P&amp;lt;field1&amp;gt;.*) (?P&amp;lt;field2&amp;gt;GAP|AGAP|UA) (?P&amp;lt;field3&amp;gt;\w+\.\w+)?\s*(?P&amp;lt;field4&amp;gt;.*$)" | eval temp=split(field4,"  ") | eval field5=mvindex(temp,0) | eval field6=mvindex(temp,1) | table details field1 field2 field5 field6 | fillnull | eval field7=if(field6=0, "PLI 31", 'field6') | replace "PLI 31" with " " in field5 | table details field1 field2 field5 field7
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/431iF4E13A842D100254/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jun 2015 14:19:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-split-a-string-into-multiple-fields-using-whitespace-as/m-p/178929#M51489</guid>
      <dc:creator>cedmarjls32</dc:creator>
      <dc:date>2015-06-26T14:19:32Z</dc:date>
    </item>
  </channel>
</rss>

