<?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 a hostname from a source path? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-a-hostname-from-a-source-path/m-p/431685#M123391</link>
    <description>&lt;P&gt;Hello , Thanks for the prompt response  it worked as expected , Have a good weekend !&lt;/P&gt;</description>
    <pubDate>Sat, 08 Dec 2018 17:16:17 GMT</pubDate>
    <dc:creator>rkatsnel</dc:creator>
    <dc:date>2018-12-08T17:16:17Z</dc:date>
    <item>
      <title>How do you extract a hostname from a source path?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-a-hostname-from-a-source-path/m-p/431681#M123387</link>
      <description>&lt;P&gt;Hello all , &lt;/P&gt;

&lt;P&gt;I've configured Splunk to monitor directory , i.e.  /usr/home/test/* for new  CSV files ( periodically  generated by  cronjob)&lt;BR /&gt;
multiple files , multiple hostnames, etc....&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;csv file format = hostname.timestamp.csv
source=  /usr/home/test/rO1234560e.timestamp.csv
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I would like to extract host name(s)  at search time from my source: &lt;/P&gt;

&lt;P&gt;as I don't have privileges  to work on  input / output stanza's &lt;/P&gt;

&lt;P&gt;the following regex &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;r\w\d{7}\w 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;will match desired host name (confirmed in regex 101). But,  in Splunk, a brand new field is created as "host_N" with no value ( i.e. it's blank).&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|regex field source = (?)r\w\d{7}\w sourcetype = csv 

|regex field source = (?)r\w\d{7}\w\.\w+\.csv )  sourcetype= csv --- the same results 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks in advance ! &lt;/P&gt;</description>
      <pubDate>Sat, 08 Dec 2018 16:24:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-a-hostname-from-a-source-path/m-p/431681#M123387</guid>
      <dc:creator>rkatsnel</dc:creator>
      <dc:date>2018-12-08T16:24:18Z</dc:date>
    </item>
    <item>
      <title>Re: How do you extract a hostname from a source path?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-a-hostname-from-a-source-path/m-p/431682#M123388</link>
      <description>&lt;P&gt;Hi! You are confusing the &lt;STRONG&gt;regex&lt;/STRONG&gt; command with the &lt;STRONG&gt;rex&lt;/STRONG&gt; command. The &lt;STRONG&gt;regex&lt;/STRONG&gt; command is for removing results based on a regular expression. The &lt;STRONG&gt;rex&lt;/STRONG&gt; command (this is what you need) is for extracting new fields at search time.&lt;/P&gt;

&lt;P&gt;Try it like this. The new field will be named "hostname":&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=... sourcetype=csv | rex field=source "(?&amp;lt;hostname&amp;gt;r\w\d{7}\w)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Instead of doing the field extraction at search time, you could create a new field extraction under "Settings / Fields / Field extractions" or when clicking on "Event Actions / Extract Fields" in the search window. That way, Splunk will extract the field automatically for you.&lt;/P&gt;

&lt;P&gt;EDIT: Typo&lt;/P&gt;</description>
      <pubDate>Sat, 08 Dec 2018 16:52:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-a-hostname-from-a-source-path/m-p/431682#M123388</guid>
      <dc:creator>whrg</dc:creator>
      <dc:date>2018-12-08T16:52:17Z</dc:date>
    </item>
    <item>
      <title>Re: How do you extract a hostname from a source path?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-a-hostname-from-a-source-path/m-p/431683#M123389</link>
      <description>&lt;P&gt;I tried what you have  suggested and it does not work , my guess  it's was a typo -:) , Thanks for for your help &lt;/P&gt;</description>
      <pubDate>Sat, 08 Dec 2018 16:59:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-a-hostname-from-a-source-path/m-p/431683#M123389</guid>
      <dc:creator>rkatsnel</dc:creator>
      <dc:date>2018-12-08T16:59:13Z</dc:date>
    </item>
    <item>
      <title>Re: How do you extract a hostname from a source path?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-a-hostname-from-a-source-path/m-p/431684#M123390</link>
      <description>&lt;P&gt;new field extraction is a terrific idea , Thanks for that !&lt;/P&gt;</description>
      <pubDate>Sat, 08 Dec 2018 17:05:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-a-hostname-from-a-source-path/m-p/431684#M123390</guid>
      <dc:creator>rkatsnel</dc:creator>
      <dc:date>2018-12-08T17:05:28Z</dc:date>
    </item>
    <item>
      <title>Re: How do you extract a hostname from a source path?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-a-hostname-from-a-source-path/m-p/431685#M123391</link>
      <description>&lt;P&gt;Hello , Thanks for the prompt response  it worked as expected , Have a good weekend !&lt;/P&gt;</description>
      <pubDate>Sat, 08 Dec 2018 17:16:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-a-hostname-from-a-source-path/m-p/431685#M123391</guid>
      <dc:creator>rkatsnel</dc:creator>
      <dc:date>2018-12-08T17:16:17Z</dc:date>
    </item>
    <item>
      <title>Re: How do you extract a hostname from a source path?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-a-hostname-from-a-source-path/m-p/431686#M123392</link>
      <description>&lt;P&gt;True, I had a typo in there. I fixed it. Try it again.&lt;/P&gt;</description>
      <pubDate>Sat, 08 Dec 2018 17:16:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-a-hostname-from-a-source-path/m-p/431686#M123392</guid>
      <dc:creator>whrg</dc:creator>
      <dc:date>2018-12-08T17:16:21Z</dc:date>
    </item>
    <item>
      <title>Re: How do you extract a hostname from a source path?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-a-hostname-from-a-source-path/m-p/431687#M123393</link>
      <description>&lt;P&gt;Glad to hear it's working!&lt;BR /&gt;
When you add a new field extraction via Settings / Fields, set the sourcetype to csv and set Extraction/Transform to:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?&amp;lt;hostname&amp;gt;r\w\d{7}\w) in source
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 08 Dec 2018 18:08:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-extract-a-hostname-from-a-source-path/m-p/431687#M123393</guid>
      <dc:creator>whrg</dc:creator>
      <dc:date>2018-12-08T18:08:23Z</dc:date>
    </item>
  </channel>
</rss>

