<?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: trim out field using replace in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/trim-out-field-using-replace/m-p/377820#M110785</link>
    <description>&lt;P&gt;thx xpac for responding. the regular expression you provided me resulting in host field blank. I have the right answer now. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 30 Apr 2018 20:18:27 GMT</pubDate>
    <dc:creator>brdr</dc:creator>
    <dc:date>2018-04-30T20:18:27Z</dc:date>
    <item>
      <title>trim out field using replace</title>
      <link>https://community.splunk.com/t5/Splunk-Search/trim-out-field-using-replace/m-p/377816#M110781</link>
      <description>&lt;P&gt;I'm reading from a file that has messages like these:&lt;/P&gt;

&lt;P&gt;Action (0x00000173): x.x.x.x; |Performed by user "User 1"&lt;BR /&gt;
Action (0x00000173): host2.domain.com; |Performed by user "User 2"&lt;BR /&gt;
Action (0x00000173): host3.CA.domain.com; |Performed by user "User 3"&lt;/P&gt;

&lt;P&gt;After the lookup is done I have parsed out the host identifier (as either x.x.x.x, host2.domain.com, host3.CA.domain.com) as field &lt;STRONG&gt;host&lt;/STRONG&gt;. Now I need to perform actions. If the host value is an IP address then do nothing. However, if the host value is not an IP address then strip off everything (and including .) after the first period.&lt;/P&gt;

&lt;P&gt;I think the replace command will work but not getting it right... I have:&lt;/P&gt;

&lt;P&gt;| eval host=if(match(host, "^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$"), host, replace(host, 'do something here', 'do somethinge here'))&lt;/P&gt;

&lt;P&gt;In the end I should I have:&lt;BR /&gt;
x.x.x.x&lt;BR /&gt;
host2&lt;BR /&gt;
host3&lt;/P&gt;

&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Mon, 30 Apr 2018 19:57:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/trim-out-field-using-replace/m-p/377816#M110781</guid>
      <dc:creator>brdr</dc:creator>
      <dc:date>2018-04-30T19:57:16Z</dc:date>
    </item>
    <item>
      <title>Re: trim out field using replace</title>
      <link>https://community.splunk.com/t5/Splunk-Search/trim-out-field-using-replace/m-p/377817#M110782</link>
      <description>&lt;P&gt;Give this a try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval host=if(match(host, "^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$"), host, replace(host, "^([^\.]+)\..+","\1"))
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 30 Apr 2018 20:11:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/trim-out-field-using-replace/m-p/377817#M110782</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-04-30T20:11:14Z</dc:date>
    </item>
    <item>
      <title>Re: trim out field using replace</title>
      <link>https://community.splunk.com/t5/Splunk-Search/trim-out-field-using-replace/m-p/377818#M110783</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval host="host3.CA.domain.com"
| eval host=if(match(host, "^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$"), host, replace(host, "^([^\.]+)\..*$", "\1"))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;More explanation &lt;A href="http://docs.splunk.com/Documentation/Splunk/7.1.0/SearchReference/TextFunctions#replace.28X.2CY.2CZ.29"&gt;here&lt;/A&gt; in the docs, explanation of the regex &lt;A href="https://regex101.com/r/d8jguM/1"&gt;here&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Apr 2018 20:11:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/trim-out-field-using-replace/m-p/377818#M110783</guid>
      <dc:creator>xpac</dc:creator>
      <dc:date>2018-04-30T20:11:49Z</dc:date>
    </item>
    <item>
      <title>Re: trim out field using replace</title>
      <link>https://community.splunk.com/t5/Splunk-Search/trim-out-field-using-replace/m-p/377819#M110784</link>
      <description>&lt;P&gt;Thanks somesoni2! work perfectly.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Apr 2018 20:16:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/trim-out-field-using-replace/m-p/377819#M110784</guid>
      <dc:creator>brdr</dc:creator>
      <dc:date>2018-04-30T20:16:58Z</dc:date>
    </item>
    <item>
      <title>Re: trim out field using replace</title>
      <link>https://community.splunk.com/t5/Splunk-Search/trim-out-field-using-replace/m-p/377820#M110785</link>
      <description>&lt;P&gt;thx xpac for responding. the regular expression you provided me resulting in host field blank. I have the right answer now. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Apr 2018 20:18:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/trim-out-field-using-replace/m-p/377820#M110785</guid>
      <dc:creator>brdr</dc:creator>
      <dc:date>2018-04-30T20:18:27Z</dc:date>
    </item>
  </channel>
</rss>

