<?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 to make the search dynamic - continuation of &amp;quot;How to use rex and sed to insert '-' and ':' in the result?&amp;quot; in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-make-the-search-dynamic-continuation-of-quot-How-to-use/m-p/178797#M51438</link>
    <description>&lt;P&gt;How 'bout this?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex field=source "(?&amp;lt;date&amp;gt;\d+)\.log$"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That will grab the last bunch of digits before the &lt;CODE&gt;.log&lt;/CODE&gt; at the end.&lt;/P&gt;</description>
    <pubDate>Fri, 26 Jun 2015 09:17:27 GMT</pubDate>
    <dc:creator>martin_mueller</dc:creator>
    <dc:date>2015-06-26T09:17:27Z</dc:date>
    <item>
      <title>How to make the search dynamic - continuation of "How to use rex and sed to insert '-' and ':' in the result?"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-make-the-search-dynamic-continuation-of-quot-How-to-use/m-p/178796#M51437</link>
      <description>&lt;P&gt;I have different environments. In each environment logs are located in different path. e.g.:&lt;BR /&gt;
C:\Program Files\Splunk...\etc\apps......\abc-20150626123001.log&lt;BR /&gt;
/u01/splunk/...../etc/apps/...../def-20150626044921.log&lt;BR /&gt;
/u01/log02/splunk/...../etc/apps/...../mno-20150626071656.log&lt;BR /&gt;
/u02/splunk/...../etc/apps/...../xyz-20150626044921.log&lt;/P&gt;

&lt;P&gt;I am using this query -&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="myindex" | dedup source | sort -source | dedup sourcetype | table sourcetype, source
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It gives me the result but contains the complete log path. My requirement is to remove everything and display only the date and time e.g. 2015-06-26 12:30:01&lt;/P&gt;

&lt;P&gt;Thanks for answering my previous question [@richgalloway] --&amp;gt; /answers.splunk.com/answers/243218/how-to-use-rex-and-sed-to-insert-and-in-the-result.html&lt;BR /&gt;
I was able to capture the date and time by using sed and regular expression. e.g.:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="myindex" | dedup source | sort -source | dedup sourcetype | rex field=source mode=sed "s/[^0-9]*//g" | rex field=source mode=sed "s/(.{4})(.{2})(.{2})/\1-\2-\3 /" | rex field=source mode=sed "s/(.{10})(.{3})(.{2})/\1 \2:\3:/" | table sourcetype, source
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This worked only for log files present in "C:\Program Files...."&lt;/P&gt;

&lt;P&gt;However it didn't work for other environments. I had to modify each time, e.g. when it's /u01, i used -&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="myindex" | dedup source | sort -source | dedup sourcetype | rex field=source mode=sed "s/01//" | rex field=source mode=sed "s/[^0-9]*//g" | rex field=source mode=sed "s/(.{4})(.{2})(.{2})/\1-\2-\3 /" | rex field=source mode=sed "s/(.{10})(.{3})(.{2})/\1 \2:\3:/" | table sourcetype, source
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Basically I just need to capture the YYYYMMDDHHMMSS before .log and remove everything else. The app will be used by various teams. Each team will have their own folder structure. Is there a way to make the query work in any environment irrespective of the path?&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jun 2015 08:52:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-make-the-search-dynamic-continuation-of-quot-How-to-use/m-p/178796#M51437</guid>
      <dc:creator>nilotpaldutta</dc:creator>
      <dc:date>2015-06-26T08:52:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to make the search dynamic - continuation of "How to use rex and sed to insert '-' and ':' in the result?"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-make-the-search-dynamic-continuation-of-quot-How-to-use/m-p/178797#M51438</link>
      <description>&lt;P&gt;How 'bout this?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex field=source "(?&amp;lt;date&amp;gt;\d+)\.log$"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That will grab the last bunch of digits before the &lt;CODE&gt;.log&lt;/CODE&gt; at the end.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jun 2015 09:17:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-make-the-search-dynamic-continuation-of-quot-How-to-use/m-p/178797#M51438</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2015-06-26T09:17:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to make the search dynamic - continuation of "How to use rex and sed to insert '-' and ':' in the result?"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-make-the-search-dynamic-continuation-of-quot-How-to-use/m-p/178798#M51439</link>
      <description>&lt;P&gt;Can you please write the whole query?&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jun 2015 10:21:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-make-the-search-dynamic-continuation-of-quot-How-to-use/m-p/178798#M51439</guid>
      <dc:creator>nilotpaldutta</dc:creator>
      <dc:date>2015-06-26T10:21:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to make the search dynamic - continuation of "How to use rex and sed to insert '-' and ':' in the result?"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-make-the-search-dynamic-continuation-of-quot-How-to-use/m-p/178799#M51440</link>
      <description>&lt;P&gt;I don't know what you're trying to achieve with your whole query, so this is just a guess:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| tstats count where index=myindex by source sourcetype | rex field=source "(?&amp;lt;date&amp;gt;\d+)\.log$
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 Jun 2015 11:02:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-make-the-search-dynamic-continuation-of-quot-How-to-use/m-p/178799#M51440</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2015-06-26T11:02:01Z</dc:date>
    </item>
  </channel>
</rss>

