<?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 extract the duration in seconds from values like &amp;quot;2 dy 13 hr 49 min 13 sec&amp;quot; in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-duration-in-seconds-from-values-like-quot-2/m-p/253019#M75721</link>
    <description>&lt;P&gt;Awesome, this works fine &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
Thanks a lot&lt;/P&gt;</description>
    <pubDate>Thu, 19 May 2016 13:02:54 GMT</pubDate>
    <dc:creator>HeinzWaescher</dc:creator>
    <dc:date>2016-05-19T13:02:54Z</dc:date>
    <item>
      <title>How to extract the duration in seconds from values like "2 dy 13 hr 49 min 13 sec"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-duration-in-seconds-from-values-like-quot-2/m-p/253011#M75713</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I would like to extract the duration in seconds from values like these:&lt;BR /&gt;
"2 dy 13 hr 49 min 13 sec"&lt;BR /&gt;
"1 hr 49 min 41 sec"&lt;BR /&gt;
"12 min 56 sec"&lt;/P&gt;

&lt;P&gt;For constant values (e.g. with only min &amp;amp; sec) I would use:&lt;BR /&gt;
"12 min 56 sec" -&amp;gt; &lt;CODE&gt;| rex field="FieldA" "(?.*)\ (?.*)\ (?.*) (?.*)"&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;But as you can see, the format can be different. Is possible to convert these fields into a duration in seconds?&lt;/P&gt;

&lt;P&gt;My idea would be to extract fields for each part of the value, for example:&lt;/P&gt;

&lt;P&gt;"2 dy 13 hr 49 min 13 sec" into:&lt;/P&gt;

&lt;P&gt;dy=2&lt;BR /&gt;
hr=13&lt;BR /&gt;
min=49&lt;BR /&gt;
sec=13&lt;/P&gt;

&lt;P&gt;But I don't know how to achieve this. Can you help me?&lt;/P&gt;

&lt;P&gt;Thanks in advance&lt;BR /&gt;
Heinz&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2016 08:15:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-duration-in-seconds-from-values-like-quot-2/m-p/253011#M75713</guid>
      <dc:creator>HeinzWaescher</dc:creator>
      <dc:date>2016-05-18T08:15:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the duration in seconds from values like "2 dy 13 hr 49 min 13 sec"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-duration-in-seconds-from-values-like-quot-2/m-p/253012#M75714</link>
      <description>&lt;P&gt;Hi HeinzWasecher,&lt;/P&gt;

&lt;P&gt;Have you try to use separate extractions like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;props.conf
EXTRACT-dias = \s(?&amp;lt;days&amp;gt;[^\s]+)\sdy
EXTRACT-horas = \s(?&amp;lt;hours&amp;gt;[^\s]+)\shr
...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And in the search make a fillnull of all the fields and make an eval with the calculation&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|fillnull days hours .... value=0
| eval Totalsec = days*86400 + hours*3600 ....
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope i help you&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2016 08:30:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-duration-in-seconds-from-values-like-quot-2/m-p/253012#M75714</guid>
      <dc:creator>jmallorquin</dc:creator>
      <dc:date>2016-05-18T08:30:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the duration in seconds from values like "2 dy 13 hr 49 min 13 sec"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-duration-in-seconds-from-values-like-quot-2/m-p/253013#M75715</link>
      <description>&lt;P&gt;Thanks for your answer. I'm using a csv with inputlookup here, so I think I have to do it at search time?&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2016 08:32:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-duration-in-seconds-from-values-like-quot-2/m-p/253013#M75715</guid>
      <dc:creator>HeinzWaescher</dc:creator>
      <dc:date>2016-05-18T08:32:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the duration in seconds from values like "2 dy 13 hr 49 min 13 sec"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-duration-in-seconds-from-values-like-quot-2/m-p/253014#M75716</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;Yes. I that case it will be &lt;BR /&gt;
    | rex "\s(?&lt;DAYS&gt;[^\s]+)\sdy" |rex "\s(?&lt;HOURS&gt;[^\s]+)\shr" ....&lt;/HOURS&gt;&lt;/DAYS&gt;&lt;/P&gt;

&lt;P&gt;Hope i help you&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2016 09:03:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-duration-in-seconds-from-values-like-quot-2/m-p/253014#M75716</guid>
      <dc:creator>jmallorquin</dc:creator>
      <dc:date>2016-05-18T09:03:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the duration in seconds from values like "2 dy 13 hr 49 min 13 sec"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-duration-in-seconds-from-values-like-quot-2/m-p/253015#M75717</link>
      <description>&lt;P&gt;This results in an error:&lt;/P&gt;

&lt;P&gt;Error in 'rex' command: Encountered the following error while compiling the regex '\s(?[^\s]+)\sdy': Regex: unrecognized character after (? or (?- &lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2016 09:09:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-duration-in-seconds-from-values-like-quot-2/m-p/253015#M75717</guid>
      <dc:creator>HeinzWaescher</dc:creator>
      <dc:date>2016-05-18T09:09:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the duration in seconds from values like "2 dy 13 hr 49 min 13 sec"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-duration-in-seconds-from-values-like-quot-2/m-p/253016#M75718</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;

&lt;P&gt;.... | eval duration= replace(duration,"(\d*)+?(\d+):(\d+):(\d+)","\1dy \2hr \3min \4sec")&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2016 17:29:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-duration-in-seconds-from-values-like-quot-2/m-p/253016#M75718</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-05-18T17:29:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the duration in seconds from values like "2 dy 13 hr 49 min 13 sec"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-duration-in-seconds-from-values-like-quot-2/m-p/253017#M75719</link>
      <description>&lt;P&gt;Thanks for your suggestion. I'm not sure what is intended by this command, adding it just copies the field.&lt;/P&gt;

&lt;P&gt;duration="14 hr 22 min 44 sec" -&amp;gt; new duration="14 hr 22 min 44 sec"&lt;/P&gt;</description>
      <pubDate>Thu, 19 May 2016 05:47:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-duration-in-seconds-from-values-like-quot-2/m-p/253017#M75719</guid>
      <dc:creator>HeinzWaescher</dc:creator>
      <dc:date>2016-05-19T05:47:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the duration in seconds from values like "2 dy 13 hr 49 min 13 sec"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-duration-in-seconds-from-values-like-quot-2/m-p/253018#M75720</link>
      <description>&lt;P&gt;LOL. I clearly misunderstood your question. Here, I think I know now, what you are looking for. Try this runanywhere sample&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1 | eval duration="49 min 13 sec" | rex field=duration "((?&amp;lt;dy&amp;gt;\d+)\sdy\s)?((?&amp;lt;hr&amp;gt;\d+)\shr\s)?((?&amp;lt;min&amp;gt;\d+)\smin\s)?((?&amp;lt;sec&amp;gt;\d+)\ssec)?" | eval dy=coalesce(dy, 0) | eval hr=coalesce(hr, 0) | eval min=coalesce(min, 0) | eval sec=coalesce(sec, 0) | eval duration=(dy*(3600*24)) + (hr*(3600)) + (min*60) + sec | eval dur=tostring(duration, "duration") | table dy hr min sec duration dur
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 May 2016 12:10:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-duration-in-seconds-from-values-like-quot-2/m-p/253018#M75720</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-05-19T12:10:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the duration in seconds from values like "2 dy 13 hr 49 min 13 sec"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-duration-in-seconds-from-values-like-quot-2/m-p/253019#M75721</link>
      <description>&lt;P&gt;Awesome, this works fine &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
Thanks a lot&lt;/P&gt;</description>
      <pubDate>Thu, 19 May 2016 13:02:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-duration-in-seconds-from-values-like-quot-2/m-p/253019#M75721</guid>
      <dc:creator>HeinzWaescher</dc:creator>
      <dc:date>2016-05-19T13:02:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the duration in seconds from values like "2 dy 13 hr 49 min 13 sec"</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-duration-in-seconds-from-values-like-quot-2/m-p/253020#M75722</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;Sorry I didn't quote and the command was malformed&lt;/P&gt;

&lt;P&gt;The correct is :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex "\s(?&amp;lt;days&amp;gt;[^\s]+)\sdy" |rex "\s(?&amp;lt;hours&amp;gt;[^\s]+)\shr" ....&amp;lt;-- continue with the rest of the fields
|fillnull days hours .... value=0
| eval Totalsec = days*86400 + hours*3600 ....
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 May 2016 13:03:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-duration-in-seconds-from-values-like-quot-2/m-p/253020#M75722</guid>
      <dc:creator>jmallorquin</dc:creator>
      <dc:date>2016-05-19T13:03:06Z</dc:date>
    </item>
  </channel>
</rss>

