<?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 How do I replace text within a field with text from another field? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-replace-text-within-a-field-with-text-from-another/m-p/448427#M127049</link>
    <description>&lt;P&gt;I have events that contain multiple fields. For example&lt;/P&gt;

&lt;P&gt;PARAM1:  Thing1&lt;BR /&gt;
PARAM2:  Thing2&lt;BR /&gt;
PARAM3:  Thing3&lt;BR /&gt;
MESSAGE:  Refer to P1 and P2 in conjunction with P3 and escalate as need be.  &lt;/P&gt;

&lt;P&gt;What I'd like to create is a message that populates with everything in one sentence / field.  &lt;/P&gt;

&lt;P&gt;For example:&lt;/P&gt;

&lt;P&gt;MESSAGE:  Refer to Thing1 and Thing2 in conjunction with Thing3 and escalate as need be.&lt;/P&gt;

&lt;P&gt;Any suggestions on how to make this happen would be greatly appreciated.&lt;/P&gt;</description>
    <pubDate>Thu, 07 Feb 2019 20:47:23 GMT</pubDate>
    <dc:creator>cquinney</dc:creator>
    <dc:date>2019-02-07T20:47:23Z</dc:date>
    <item>
      <title>How do I replace text within a field with text from another field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-replace-text-within-a-field-with-text-from-another/m-p/448427#M127049</link>
      <description>&lt;P&gt;I have events that contain multiple fields. For example&lt;/P&gt;

&lt;P&gt;PARAM1:  Thing1&lt;BR /&gt;
PARAM2:  Thing2&lt;BR /&gt;
PARAM3:  Thing3&lt;BR /&gt;
MESSAGE:  Refer to P1 and P2 in conjunction with P3 and escalate as need be.  &lt;/P&gt;

&lt;P&gt;What I'd like to create is a message that populates with everything in one sentence / field.  &lt;/P&gt;

&lt;P&gt;For example:&lt;/P&gt;

&lt;P&gt;MESSAGE:  Refer to Thing1 and Thing2 in conjunction with Thing3 and escalate as need be.&lt;/P&gt;

&lt;P&gt;Any suggestions on how to make this happen would be greatly appreciated.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Feb 2019 20:47:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-replace-text-within-a-field-with-text-from-another/m-p/448427#M127049</guid>
      <dc:creator>cquinney</dc:creator>
      <dc:date>2019-02-07T20:47:23Z</dc:date>
    </item>
    <item>
      <title>Re: How do I replace text within a field with text from another field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-replace-text-within-a-field-with-text-from-another/m-p/448428#M127050</link>
      <description>&lt;P&gt;I answered this question the other day for someone. I'm going t assume you want to do this at search time, not index time. The other assumption I'm going to make is that these values are all in the same event. And one final assumption is that the event has the same order each time for the parameters that you want to use.&lt;/P&gt;

&lt;P&gt;You will want to use the &lt;CODE&gt;rex&lt;/CODE&gt; command with &lt;CODE&gt;mode=sed&lt;/CODE&gt; so that it will actually do the substitution inside the value of the Message field. Something like this can do what you want (and this is using data exactly as you have it above. If it is different, adjust):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval data="PARAM1: Thing1
PARAM2: Thing2
PARAM3: Thing3
MESSAGE: Refer to P1 and P2 in conjunction with P3 and escalate as need be." |
rex mode=sed field=data 
"s/(PARAM1: )(\w+)([\s\S]*PARAM2: )(\w+)([\s\S]*PARAM3: )(\w+)([\s\S]*MESSAGE: )(.*)P1(.*)P2/\1\2\3\4\5\6\7\8\2\9\4/"
| rex mode=sed field=data "s/(PARAM3: )(\w+)([\s\S]*MESSAGE: )(.*)P3/\1\2\3\4\2/"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The rex command is the only real necessary part. The rest is just setting up the data. This is a general case solution given the data that you provided above. &lt;/P&gt;</description>
      <pubDate>Thu, 07 Feb 2019 22:47:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-replace-text-within-a-field-with-text-from-another/m-p/448428#M127050</guid>
      <dc:creator>cpetterborg</dc:creator>
      <dc:date>2019-02-07T22:47:35Z</dc:date>
    </item>
    <item>
      <title>Re: How do I replace text within a field with text from another field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-replace-text-within-a-field-with-text-from-another/m-p/448429#M127051</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 07 Feb 2019 23:07:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-replace-text-within-a-field-with-text-from-another/m-p/448429#M127051</guid>
      <dc:creator>cquinney</dc:creator>
      <dc:date>2019-02-07T23:07:26Z</dc:date>
    </item>
  </channel>
</rss>

