<?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: Use strftime eval in same query in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Use-strftime-eval-in-same-query/m-p/465838#M131195</link>
    <description>&lt;P&gt;Why do you think you need a subsearch?  How is the first query failing you?&lt;BR /&gt;
Does 'nowstr' contain quotes?  If not, that may explain the failure.&lt;/P&gt;</description>
    <pubDate>Thu, 24 Oct 2019 22:19:40 GMT</pubDate>
    <dc:creator>richgalloway</dc:creator>
    <dc:date>2019-10-24T22:19:40Z</dc:date>
    <item>
      <title>Use strftime eval in same query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Use-strftime-eval-in-same-query/m-p/465837#M131194</link>
      <description>&lt;P&gt;I am trying to create a search that evaluates today's date and uses that output string/field as part of the search: &lt;/P&gt;

&lt;BLOCKQUOTE&gt;**sourcetype=named | eval nowstr="(serial ".strftime(now(), "%Y%m%d")."02)" | search nowstr**&lt;/BLOCKQUOTE&gt;

&lt;P&gt;The unique string needed is &lt;STRONG&gt;"(serial 2019102402)"&lt;/STRONG&gt; and I've confirmed the field "&lt;EM&gt;nowstr&lt;/EM&gt;" is that exact string. I think I need a &lt;EM&gt;subsearch&lt;/EM&gt; but cannot get it working:&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;sourcetype=named &lt;BR /&gt; [ | gentimes start=-1 | eval nowstr="(serial ".strftime(now(), "%Y%m%d")."02)" | table nowstr ]&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;LOG EVENT&lt;/STRONG&gt;&lt;BR /&gt;
&lt;/P&gt;&lt;BLOCKQUOTE&gt;HOSTNAME named[32473]: 24-Oct-2019 09:00:10.656 notify: info: zone example.com/IN: sending notifies (serial 2019102402)&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2019 20:28:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Use-strftime-eval-in-same-query/m-p/465837#M131194</guid>
      <dc:creator>jsmithn</dc:creator>
      <dc:date>2019-10-24T20:28:46Z</dc:date>
    </item>
    <item>
      <title>Re: Use strftime eval in same query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Use-strftime-eval-in-same-query/m-p/465838#M131195</link>
      <description>&lt;P&gt;Why do you think you need a subsearch?  How is the first query failing you?&lt;BR /&gt;
Does 'nowstr' contain quotes?  If not, that may explain the failure.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2019 22:19:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Use-strftime-eval-in-same-query/m-p/465838#M131195</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2019-10-24T22:19:40Z</dc:date>
    </item>
    <item>
      <title>Re: Use strftime eval in same query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Use-strftime-eval-in-same-query/m-p/465839#M131196</link>
      <description>&lt;P&gt;You can use a subsearch of &lt;CODE&gt;makeresults&lt;/CODE&gt;. You apply your &lt;CODE&gt;eval nowstr="serial ".strftime(now(), "%Y%m%d")."02)"&lt;/CODE&gt; within the makeresults and do a &lt;CODE&gt;return $nowstr&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;In the end something like this:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;Search sourcetype=named [ | makeresults | eval nowstr="serial ".strftime(now(), "%Y%m%d")."02)" | return $nowstr]&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Let me know&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2019 22:23:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Use-strftime-eval-in-same-query/m-p/465839#M131196</guid>
      <dc:creator>tiagofbmm</dc:creator>
      <dc:date>2019-10-24T22:23:44Z</dc:date>
    </item>
    <item>
      <title>Re: Use strftime eval in same query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Use-strftime-eval-in-same-query/m-p/465840#M131197</link>
      <description>&lt;P&gt;Trying that "&lt;EM&gt;Error in 'search' command: Unable to parse the search: unbalanced parentheses.&lt;/EM&gt;". But I did not know about the &lt;STRONG&gt;return&lt;/STRONG&gt; command, using that I was able to get it to work. There's likely a better, more elegant solution, but it returns the results expected! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2019 00:16:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Use-strftime-eval-in-same-query/m-p/465840#M131197</guid>
      <dc:creator>jsmithn</dc:creator>
      <dc:date>2019-10-25T00:16:35Z</dc:date>
    </item>
    <item>
      <title>Re: Use strftime eval in same query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Use-strftime-eval-in-same-query/m-p/465841#M131198</link>
      <description>&lt;P&gt;Also works with either "makeresults" or "gentimes start=-1". I don't know the difference, if one is better (more economical for search).&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2019 00:19:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Use-strftime-eval-in-same-query/m-p/465841#M131198</guid>
      <dc:creator>jsmithn</dc:creator>
      <dc:date>2019-10-25T00:19:44Z</dc:date>
    </item>
    <item>
      <title>Re: Use strftime eval in same query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Use-strftime-eval-in-same-query/m-p/465842#M131199</link>
      <description>&lt;P&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;sourcetype=named &lt;BR /&gt;[ | gentimes start=-1 | eval nowstr="(serial ".strftime(now(), "%Y%m%d")."02)" | return $nowstr ] "(serial"&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;Not really sure what's happening but it works. Thanks to &lt;STRONG&gt;tiagofbmm&lt;/STRONG&gt; for moving it along. Can replace "gentimes start=-1" with "makresults" but unknown if one is better.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2019 00:25:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Use-strftime-eval-in-same-query/m-p/465842#M131199</guid>
      <dc:creator>jsmithn</dc:creator>
      <dc:date>2019-10-25T00:25:48Z</dc:date>
    </item>
    <item>
      <title>Re: Use strftime eval in same query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Use-strftime-eval-in-same-query/m-p/465843#M131200</link>
      <description>&lt;P&gt;I think that because of other posts in the community, seems like a subsearch is the way to accomplish what I want. The first query does not yield any results. 'nowstr' is defined by my statement above. Using today's date, its value is &lt;STRONG&gt;(serial 2019102402)&lt;/STRONG&gt;. No quotes.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2019 00:27:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Use-strftime-eval-in-same-query/m-p/465843#M131200</guid>
      <dc:creator>jsmithn</dc:creator>
      <dc:date>2019-10-25T00:27:27Z</dc:date>
    </item>
    <item>
      <title>Re: Use strftime eval in same query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Use-strftime-eval-in-same-query/m-p/465844#M131201</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval nowstr="(serial ".strftime(now(), "%Y%m%d")."02)"
| map search="search index=YouShouldAlwaysSpecifyAnIndex AND sourcetype=named $nowstr$"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 26 Oct 2019 00:18:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Use-strftime-eval-in-same-query/m-p/465844#M131201</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-10-26T00:18:16Z</dc:date>
    </item>
  </channel>
</rss>

