<?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: Extract time from log in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Extract-time-from-log/m-p/496429#M194661</link>
    <description>&lt;P&gt;Hi&lt;/P&gt;

&lt;P&gt;Try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval temp="2019-12-03 14:20:55,679 ------------------ Begin Request -----------------" 
| rex field=temp "\d{4}-\d{2}-\d{2}\s(?P&amp;lt;beginTime&amp;gt;\d{2}:\d{2}:\d{2})"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 04 Dec 2019 02:47:25 GMT</pubDate>
    <dc:creator>vnravikumar</dc:creator>
    <dc:date>2019-12-04T02:47:25Z</dc:date>
    <item>
      <title>Extract time from log</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-time-from-log/m-p/496426#M194658</link>
      <description>&lt;P&gt;Below is my data&lt;BR /&gt;
2019-12-03 14:20:55,679 ------------------ Begin Request ----------------- &lt;/P&gt;

&lt;P&gt;How do I extract begin time 14:20:55 from the above log data?&lt;/P&gt;</description>
      <pubDate>Tue, 03 Dec 2019 19:44:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-time-from-log/m-p/496426#M194658</guid>
      <dc:creator>shwetamis</dc:creator>
      <dc:date>2019-12-03T19:44:06Z</dc:date>
    </item>
    <item>
      <title>Re: Extract time from log</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-time-from-log/m-p/496427#M194659</link>
      <description>&lt;P&gt;If you're sure that is the raw format for all of your logs, you can write a simple regex leveraging the &lt;CODE&gt;rex&lt;/CODE&gt; command &lt;A href="https://docs.splunk.com/Documentation/Splunk/8.0.0/SearchReference/Rex#Syntax" target="_blank"&gt;https://docs.splunk.com/Documentation/Splunk/8.0.0/SearchReference/Rex#Syntax&lt;/A&gt;. Rough example syntax below:&lt;/P&gt;

&lt;P&gt;{code}&lt;BR /&gt;
| makeresults count=1&lt;BR /&gt;
| eval _raw="2019-12-03 14:20:55,679 ------------------ Begin Request -----------------"&lt;BR /&gt;
| rex field=_raw ".&lt;EM&gt;\s(?.&lt;/EM&gt;),.*"&lt;/P&gt;

&lt;P&gt;{code}&lt;/P&gt;

&lt;P&gt;If you run this code, you can see that I generate a similar event to the line you posted above, and then run the &lt;CODE&gt;rex&lt;/CODE&gt; command with a capturing group around "timeStamp", which is anything after the first whitespace up until the first comma. For your case you don't need to generate the _raw field as that is just a representation of the log you already have on your machine.&lt;/P&gt;

&lt;P&gt;Why I call this "rough" syntax is you want to make sure the regex works for all of your log formats, so this means either running it against multiple logs and making sure that the timeStamp field is always populated or iterating on the regex (I like regex101.com for that, it has a workspace and good tips on the side) since you will have access to more log information than me. In general, using the &lt;CODE&gt;rex&lt;/CODE&gt; command is a great way to extract information from a string in Splunk though!&lt;/P&gt;

&lt;P&gt;Hope this helps!&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 03:14:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-time-from-log/m-p/496427#M194659</guid>
      <dc:creator>aberkow</dc:creator>
      <dc:date>2020-09-30T03:14:52Z</dc:date>
    </item>
    <item>
      <title>Re: Extract time from log</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-time-from-log/m-p/496428#M194660</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval begin=strptime(_raw, "%Y-%m-%d %H:%M:%S,%3N")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Dec 2019 22:25:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-time-from-log/m-p/496428#M194660</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-12-03T22:25:58Z</dc:date>
    </item>
    <item>
      <title>Re: Extract time from log</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-time-from-log/m-p/496429#M194661</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;

&lt;P&gt;Try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval temp="2019-12-03 14:20:55,679 ------------------ Begin Request -----------------" 
| rex field=temp "\d{4}-\d{2}-\d{2}\s(?P&amp;lt;beginTime&amp;gt;\d{2}:\d{2}:\d{2})"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Dec 2019 02:47:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-time-from-log/m-p/496429#M194661</guid>
      <dc:creator>vnravikumar</dc:creator>
      <dc:date>2019-12-04T02:47:25Z</dc:date>
    </item>
    <item>
      <title>Re: Extract time from log</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-time-from-log/m-p/496430#M194662</link>
      <description>&lt;P&gt;Thank you this one worked.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2019 14:14:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-time-from-log/m-p/496430#M194662</guid>
      <dc:creator>shwetamis</dc:creator>
      <dc:date>2019-12-04T14:14:56Z</dc:date>
    </item>
    <item>
      <title>Re: Extract time from log</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-time-from-log/m-p/496431#M194663</link>
      <description>&lt;P&gt;Also I don't want to hardcode the time in the search, as it is not for one transaction, how to I do that ?&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2019 14:16:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-time-from-log/m-p/496431#M194663</guid>
      <dc:creator>shwetamis</dc:creator>
      <dc:date>2019-12-04T14:16:09Z</dc:date>
    </item>
    <item>
      <title>Re: Extract time from log</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-time-from-log/m-p/496432#M194664</link>
      <description>&lt;P&gt;I don't want to hardcode the time, as I am searching for multiple transactions&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2019 14:16:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-time-from-log/m-p/496432#M194664</guid>
      <dc:creator>shwetamis</dc:creator>
      <dc:date>2019-12-04T14:16:44Z</dc:date>
    </item>
    <item>
      <title>Re: Extract time from log</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-time-from-log/m-p/496433#M194665</link>
      <description>&lt;P&gt;is _raw field that hold values of time ? if so then it returns raw data it doesn't return the time&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2019 14:18:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-time-from-log/m-p/496433#M194665</guid>
      <dc:creator>shwetamis</dc:creator>
      <dc:date>2019-12-04T14:18:07Z</dc:date>
    </item>
  </channel>
</rss>

