<?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 to extract host field values with regex? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-host-field-values-with-regex/m-p/148194#M41425</link>
    <description>&lt;P&gt;Hello Experts,&lt;/P&gt;

&lt;P&gt;I am trying to extract hosts from the following in 2 ways&lt;BR /&gt;
15 21:26:18 &lt;STRONG&gt;cmflouxy005.sample.xy.com&lt;/STRONG&gt; storage_config_info[15580]: GETIT_Store_Reflection_data|INQ|&lt;STRONG&gt;cmflouxy005&lt;/STRONG&gt;|/dev/rdsk/A3x5000097408315E90d63s2|000292603159|2606|R1|9437760&lt;BR /&gt;
Approach # 1: i tried (^.*?\d{2}:d{2}:d{2})\s(?&lt;HOSTNAME&gt;\S+)" this gives me cmflouxy005.sample.xy.com but i need 'cmflouxy005' only.&lt;/HOSTNAME&gt;&lt;/P&gt;

&lt;P&gt;Approach # 2: Can you also help me how to extract the host value that's between the pipes on second line? by knowing both the ways, i am hoping to get a good understanding of regex and extractions involving special chars.&lt;/P&gt;

&lt;P&gt;Another roadblock: sometimes i have IP addresses in place of FQDN in the logs.&lt;BR /&gt;
Thanks in advance,&lt;BR /&gt;
Raghav&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 17:07:05 GMT</pubDate>
    <dc:creator>Raghav2384</dc:creator>
    <dc:date>2020-09-28T17:07:05Z</dc:date>
    <item>
      <title>How to extract host field values with regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-host-field-values-with-regex/m-p/148194#M41425</link>
      <description>&lt;P&gt;Hello Experts,&lt;/P&gt;

&lt;P&gt;I am trying to extract hosts from the following in 2 ways&lt;BR /&gt;
15 21:26:18 &lt;STRONG&gt;cmflouxy005.sample.xy.com&lt;/STRONG&gt; storage_config_info[15580]: GETIT_Store_Reflection_data|INQ|&lt;STRONG&gt;cmflouxy005&lt;/STRONG&gt;|/dev/rdsk/A3x5000097408315E90d63s2|000292603159|2606|R1|9437760&lt;BR /&gt;
Approach # 1: i tried (^.*?\d{2}:d{2}:d{2})\s(?&lt;HOSTNAME&gt;\S+)" this gives me cmflouxy005.sample.xy.com but i need 'cmflouxy005' only.&lt;/HOSTNAME&gt;&lt;/P&gt;

&lt;P&gt;Approach # 2: Can you also help me how to extract the host value that's between the pipes on second line? by knowing both the ways, i am hoping to get a good understanding of regex and extractions involving special chars.&lt;/P&gt;

&lt;P&gt;Another roadblock: sometimes i have IP addresses in place of FQDN in the logs.&lt;BR /&gt;
Thanks in advance,&lt;BR /&gt;
Raghav&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 17:07:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-host-field-values-with-regex/m-p/148194#M41425</guid>
      <dc:creator>Raghav2384</dc:creator>
      <dc:date>2020-09-28T17:07:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract host field values with regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-host-field-values-with-regex/m-p/148195#M41426</link>
      <description>&lt;P&gt;You could use like this, didn't test 100% but it should select the IP or the first part of the FQDN.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;^\d+\s\d{2}:\d{2}:\d{2}\s(?&amp;lt;hostname&amp;gt;((\d+\.\d+\.\d+\.\d+|\w+)))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;for the second line, with the Pipes, you can use:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;^\w+\|\w+\|(?&amp;lt;hostname&amp;gt;(\d+\.\d+\.\d+\.\d+|\w+))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you have the both lines on the same sourcetype, you probably want to give different names to the extracted fields.&lt;/P&gt;

&lt;P&gt;Btw, this is a good site to test RegExps:&lt;BR /&gt;
&lt;A href="http://regex101.com/#pcre"&gt;http://regex101.com/#pcre&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jul 2014 03:34:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-host-field-values-with-regex/m-p/148195#M41426</guid>
      <dc:creator>musskopf</dc:creator>
      <dc:date>2014-07-18T03:34:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract host field values with regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-host-field-values-with-regex/m-p/148196#M41427</link>
      <description>&lt;P&gt;For capturing IP, \d+ will work fine. This is probably a better example in terms of regex and not being greedy-&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;^\d+\s\d{2}:\d{2}:\d{2}\s(?&amp;lt;host&amp;gt;(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})|\w+)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And is that log actually two lines, or is it one single line event? In the later case, the second regex needs to be changed.. The below will look for the second occurrence of '|' from the beginning of the line and capture the word after that.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;^(?:[^|]*\|){2}(?&amp;lt;hostname&amp;gt;\w[^|]*)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Cheers.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jul 2014 04:42:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-host-field-values-with-regex/m-p/148196#M41427</guid>
      <dc:creator>esix_splunk</dc:creator>
      <dc:date>2014-07-18T04:42:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract host field values with regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-host-field-values-with-regex/m-p/148197#M41428</link>
      <description>&lt;P&gt;using d{1,3} instead of d+did the magic. Thank you&lt;/P&gt;</description>
      <pubDate>Sat, 19 Jul 2014 17:49:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-host-field-values-with-regex/m-p/148197#M41428</guid>
      <dc:creator>Raghav2384</dc:creator>
      <dc:date>2014-07-19T17:49:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract host field values with regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-host-field-values-with-regex/m-p/148198#M41429</link>
      <description>&lt;P&gt;it worked after i changed \d+ to \d{1,3}. For some reason the field doesn't appear in interesting fields area if i use \d+. Do you know the reason?&lt;/P&gt;

&lt;P&gt;Thank you for the link and appreciate you help.&lt;/P&gt;</description>
      <pubDate>Sat, 19 Jul 2014 17:50:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-host-field-values-with-regex/m-p/148198#M41429</guid>
      <dc:creator>Raghav2384</dc:creator>
      <dc:date>2014-07-19T17:50:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract host field values with regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-host-field-values-with-regex/m-p/148199#M41430</link>
      <description>&lt;P&gt;d+ is a greedy search in regex. So it will return 0 to infinite numbers. Ip addresses do have constraints d{1,3}. So I would image the pattern matching in your data without a proper regex wouldnt identify it properly.&lt;/P&gt;</description>
      <pubDate>Sun, 20 Jul 2014 01:53:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-host-field-values-with-regex/m-p/148199#M41430</guid>
      <dc:creator>esix_splunk</dc:creator>
      <dc:date>2014-07-20T01:53:24Z</dc:date>
    </item>
  </channel>
</rss>

