<?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 do you extract fields from an existing field's value? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-fields-from-an-existing-field-s-value/m-p/431545#M123345</link>
    <description>&lt;P&gt;Hi Raschko&lt;BR /&gt;
I put your code against production log, the first rex works fine, added ||| into the string, but the second rex commend didnt return any value in full_comments field, any suggestion why?&lt;/P&gt;

&lt;P&gt;I put the string value in your original code and it works fine as well&lt;BR /&gt;
Thank you so much for your help&lt;BR /&gt;
Cheers&lt;BR /&gt;
Sam  &lt;/P&gt;</description>
    <pubDate>Sun, 21 Oct 2018 00:39:06 GMT</pubDate>
    <dc:creator>samlinsongguo</dc:creator>
    <dc:date>2018-10-21T00:39:06Z</dc:date>
    <item>
      <title>How do you extract fields from an existing field's value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-fields-from-an-existing-field-s-value/m-p/431542#M123342</link>
      <description>&lt;P&gt;I have a field that contains one long string looks like below&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;18/10/2018 03:42:26 - Chirs Lee (Work notes) commentxxx commentxxx commentxxx commentxxx 17/10/2018 23:14:04 - Sam Smith(Work notes) commentxxx commentxxx commentxxx commentxxx 17/10/2018 23:13:33 - Bob Bob(Work notes) commentxxx commentxxx commentxxx commentxxx 15/10/2018 23:13:33 - Chris Lee (Work notes) commentxxx commentxxx commentxxx commentxxx 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This message is in one event, I want to extract 3 fields from this message: time, name, and comment which will look as below&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;time                 name       comment 
18/10/2018 03:42:26 Chirs Lee (Work notes) commentxxx commentxxx commentxxx commentxxx 
17/10/2018 23:14:04 Sam Smith (Work notes) commentxxx commentxxx commentxxx commentxxx
17/10/2018 23:13:33 Bob Bob   (Work notes) commentxxx commentxxx commentxxx commentxxx 
15/10/2018 23:13:33 Chris Lee (Work notes) commentxxx commentxxx commentxxx commentxxx
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Ideally, this one event will be split to multiple events, but I guess if it is acceptable as a field with multi value field.&lt;/P&gt;

&lt;P&gt;My final goal is that, later on, I will be able to search what comment a user (Chirs Lee) put in the job.&lt;/P&gt;

&lt;P&gt;Any suggestion how I can extract the string from this field?&lt;/P&gt;</description>
      <pubDate>Sat, 20 Oct 2018 21:52:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-fields-from-an-existing-field-s-value/m-p/431542#M123342</guid>
      <dc:creator>samlinsongguo</dc:creator>
      <dc:date>2018-10-20T21:52:52Z</dc:date>
    </item>
    <item>
      <title>Re: How do you extract fields from an existing field's value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-fields-from-an-existing-field-s-value/m-p/431543#M123343</link>
      <description>&lt;P&gt;Try the following search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=1 
| eval test="18/10/2018 03:42:26 - Chirs Lee (Work notes) commentxxx commentxxx commentxxx commentxxx 17/10/2018 23:14:04 - Sam Smith (Work notes) commentxxx commentxxx commentxxx commentxxx 17/10/2018 23:13:33 - Bob Bob (Work notes) commentxxx commentxxx commentxxx commentxxx 15/10/2018 23:13:33 - Chris Lee (Work notes) commentxxx commentxxx commentxxx commentxxx" 
| fields - _time 
| rex field=test mode=sed "s/(\d{2}\/\d{2}\/\d{4} \d{2}:\d{2}:\d{2} -)|$/|||\1/g" 
| rex field=test max_match=10 "(?&amp;lt;full_comments&amp;gt;\d{2}/\d{2}/\d{4}.*?)(?:\|\|\|)|\$"
| fields - test
| mvexpand full_comments
| rex field=full_comments "(?&amp;lt;time&amp;gt;\d{2}/\d{2}/\d{4} \d{2}:\d{2}:\d{2})\s-\s(?&amp;lt;worker&amp;gt;[^(]+)(?&amp;lt;comment&amp;gt;\(.*)"

| table time, worker, comment, full_comments
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The first &lt;STRONG&gt;rex&lt;/STRONG&gt;  command is prepending the delimiter ||| in front of every date and at the end of the string.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=test mode=sed "s/(\d{2}\/\d{2}\/\d{4} \d{2}:\d{2}:\d{2} -)|$/|||\1/g" 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The second &lt;STRONG&gt;rex&lt;/STRONG&gt; command extracts the comments until each delimiter.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=test max_match=10 "(?&amp;lt;full_comments&amp;gt;\d{2}/\d{2}/\d{4}.*?)(?:\|\|\|)|\$"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The &lt;STRONG&gt;mvexpand&lt;/STRONG&gt; splits the multi-valued comments into single-valued ones.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| mvexpand full_comments
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The last &lt;STRONG&gt;rex&lt;/STRONG&gt; command extracts your wanted fields.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=full_comments "(?&amp;lt;time&amp;gt;\d{2}/\d{2}/\d{4} \d{2}:\d{2}:\d{2})\s-\s(?&amp;lt;worker&amp;gt;[^(]+)(?&amp;lt;comment&amp;gt;\(.*)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;HTH...&lt;/P&gt;</description>
      <pubDate>Sat, 20 Oct 2018 23:35:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-fields-from-an-existing-field-s-value/m-p/431543#M123343</guid>
      <dc:creator>Raschko</dc:creator>
      <dc:date>2018-10-20T23:35:41Z</dc:date>
    </item>
    <item>
      <title>Re: How do you extract fields from an existing field's value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-fields-from-an-existing-field-s-value/m-p/431544#M123344</link>
      <description>&lt;P&gt;This is amazing, didnt expect get answer this fast, you are great&lt;/P&gt;</description>
      <pubDate>Sun, 21 Oct 2018 00:13:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-fields-from-an-existing-field-s-value/m-p/431544#M123344</guid>
      <dc:creator>samlinsongguo</dc:creator>
      <dc:date>2018-10-21T00:13:17Z</dc:date>
    </item>
    <item>
      <title>Re: How do you extract fields from an existing field's value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-fields-from-an-existing-field-s-value/m-p/431545#M123345</link>
      <description>&lt;P&gt;Hi Raschko&lt;BR /&gt;
I put your code against production log, the first rex works fine, added ||| into the string, but the second rex commend didnt return any value in full_comments field, any suggestion why?&lt;/P&gt;

&lt;P&gt;I put the string value in your original code and it works fine as well&lt;BR /&gt;
Thank you so much for your help&lt;BR /&gt;
Cheers&lt;BR /&gt;
Sam  &lt;/P&gt;</description>
      <pubDate>Sun, 21 Oct 2018 00:39:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-fields-from-an-existing-field-s-value/m-p/431545#M123345</guid>
      <dc:creator>samlinsongguo</dc:creator>
      <dc:date>2018-10-21T00:39:06Z</dc:date>
    </item>
    <item>
      <title>Re: How do you extract fields from an existing field's value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-fields-from-an-existing-field-s-value/m-p/431546#M123346</link>
      <description>&lt;P&gt;fix the problem by change second one to &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex field=work_notes max_match=10 "(?&amp;lt;full_comment&amp;gt;[\w\s\W\d]+?)(?:\|\|\|)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;not sure why, any suggestion?&lt;/P&gt;</description>
      <pubDate>Sun, 21 Oct 2018 01:24:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-fields-from-an-existing-field-s-value/m-p/431546#M123346</guid>
      <dc:creator>samlinsongguo</dc:creator>
      <dc:date>2018-10-21T01:24:00Z</dc:date>
    </item>
    <item>
      <title>Re: How do you extract fields from an existing field's value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-fields-from-an-existing-field-s-value/m-p/431547#M123347</link>
      <description>&lt;P&gt;It is hard to tell without knowing the original logs or fields. Maybe it's a problem with line end ($). &lt;/P&gt;

&lt;P&gt;I guess with your rex line, you will miss the last workers comment.&lt;/P&gt;</description>
      <pubDate>Sun, 21 Oct 2018 09:13:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-fields-from-an-existing-field-s-value/m-p/431547#M123347</guid>
      <dc:creator>Raschko</dc:creator>
      <dc:date>2018-10-21T09:13:42Z</dc:date>
    </item>
  </channel>
</rss>

