<?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: Can I provide a default value for a |rex command field extraction? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Can-I-provide-a-default-value-for-a-rex-command-field-extraction/m-p/122204#M32901</link>
    <description>&lt;P&gt;Agree jrodman - your suggestion is cleaner than what I was proposing. Thanks.&lt;/P&gt;</description>
    <pubDate>Mon, 17 Nov 2014 09:05:50 GMT</pubDate>
    <dc:creator>splunkhelp</dc:creator>
    <dc:date>2014-11-17T09:05:50Z</dc:date>
    <item>
      <title>Can I provide a default value for a |rex command field extraction?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-I-provide-a-default-value-for-a-rex-command-field-extraction/m-p/122198#M32895</link>
      <description>&lt;P&gt;Good Day!&lt;/P&gt;

&lt;P&gt;Insight would be much appreciated on the following...&lt;/P&gt;

&lt;P&gt;The data below may or may not have the occurrence of the string  'tstp'.  If 'tstp' doesn't occur, I'd like to populate the tstp_date and tst_time variables in the search below with the value  'foo'.  Is it possible, in the context of a regular expression to assign 'foo' to my variables tstp_date and tstp_time if the string 'tstp'  does not occur in the data?&lt;/P&gt;

&lt;P&gt;My data looks like....&lt;/P&gt;

&lt;P&gt;lease 1.2.3.4 {&lt;BR /&gt;
  starts 2 2014/11/11 05:47:49;&lt;BR /&gt;
  ends 2 2014/11/11 09:47:49;&lt;BR /&gt;
  tstp 2 2014/11/11 09:47:49;&lt;BR /&gt;
  cltt 2 2014/11/11 05:47:49;&lt;BR /&gt;
  binding state free;&lt;BR /&gt;
  hardware ethernet 60:33:4b:ce:83:1b;&lt;BR /&gt;
  uid "\001`3K\316\203\033";&lt;BR /&gt;
}&lt;/P&gt;

&lt;P&gt;lease 4.3.2.1 {&lt;BR /&gt;
  starts 2 2014/11/11 11:42:12;&lt;BR /&gt;
  ends 2 2014/11/11 15:42:12;&lt;BR /&gt;
  cltt 2 2014/11/11 11:42:12;&lt;BR /&gt;
  binding state active;&lt;BR /&gt;
  next binding state free;&lt;BR /&gt;
  hardware ethernet a4:c3:61:77:30:80;&lt;BR /&gt;
  uid "\001\244\303aw0\200";&lt;BR /&gt;
}&lt;/P&gt;

&lt;P&gt;My search...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;   ...|  rex "^.*?lease\s+(?&amp;lt;lease_ip&amp;gt;[\d\.]+) {\s+starts \d (?&amp;lt;start_date&amp;gt;\S+) (?&amp;lt;start_time&amp;gt;\S+?);\s+ends \d (?&amp;lt;ends_date&amp;gt;\S+) (?&amp;lt;ends_time&amp;gt;\S+?);\s+(?(?=tstp)tstp \d (?P&amp;lt;tstp_date&amp;gt;\S+) (?P&amp;lt;tstp_time&amp;gt;\S+)|)" | eval tstp_date=if(isnull(tstp_date),"foo",tstp_date)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;My logic was to lookahead for the occurrence of 'tstp', if that exists, then capture tstp_date (e.g. 2014/11/11) and tstp_time (e.g. 09:47:49). If you note above, I added the eval to take care of null valued 'tstp_date' and 'tstp_time', but this is done outside the regex.&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 18:11:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-I-provide-a-default-value-for-a-rex-command-field-extraction/m-p/122198#M32895</guid>
      <dc:creator>splunkhelp</dc:creator>
      <dc:date>2020-09-28T18:11:02Z</dc:date>
    </item>
    <item>
      <title>Re: Can I provide a default value for a |rex command field extraction?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-I-provide-a-default-value-for-a-rex-command-field-extraction/m-p/122199#M32896</link>
      <description>&lt;P&gt;I think what you are trying to do is beyond the scope of regex.  Your current approach is the best one.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Nov 2014 13:38:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-I-provide-a-default-value-for-a-rex-command-field-extraction/m-p/122199#M32896</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2014-11-14T13:38:18Z</dc:date>
    </item>
    <item>
      <title>Re: Can I provide a default value for a |rex command field extraction?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-I-provide-a-default-value-for-a-rex-command-field-extraction/m-p/122200#M32897</link>
      <description>&lt;P&gt;Thanks - I wasn't sure if I had overlooked something 'regex-wise' that might have been useful.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Nov 2014 13:52:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-I-provide-a-default-value-for-a-rex-command-field-extraction/m-p/122200#M32897</guid>
      <dc:creator>splunkhelp</dc:creator>
      <dc:date>2014-11-14T13:52:01Z</dc:date>
    </item>
    <item>
      <title>Re: Can I provide a default value for a |rex command field extraction?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-I-provide-a-default-value-for-a-rex-command-field-extraction/m-p/122201#M32898</link>
      <description>&lt;P&gt;Other alternative to your eval could be "fillnull" command.&lt;/P&gt;

&lt;P&gt;e.g. &lt;BR /&gt;
    your search with regex ...| fillnull value="foo" tstp_date&lt;/P&gt;</description>
      <pubDate>Fri, 14 Nov 2014 15:33:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-I-provide-a-default-value-for-a-rex-command-field-extraction/m-p/122201#M32898</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2014-11-14T15:33:30Z</dc:date>
    </item>
    <item>
      <title>Re: Can I provide a default value for a |rex command field extraction?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-I-provide-a-default-value-for-a-rex-command-field-extraction/m-p/122202#M32899</link>
      <description>&lt;P&gt;Agreeing with Rich here, so promoting his comment to an answer.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Nov 2014 15:41:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-I-provide-a-default-value-for-a-rex-command-field-extraction/m-p/122202#M32899</guid>
      <dc:creator>jrodman</dc:creator>
      <dc:date>2014-11-14T15:41:27Z</dc:date>
    </item>
    <item>
      <title>Re: Can I provide a default value for a |rex command field extraction?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-I-provide-a-default-value-for-a-rex-command-field-extraction/m-p/122203#M32900</link>
      <description>&lt;P&gt;As an aside, it's a little unusual that your tstp clause is written similarly to &lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;(what i want|)&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;I think it's a little more idiomatic to do&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;(what i want)?&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Also I think the leading &lt;CODE&gt;?&lt;/CODE&gt; inside the group is a stray character?&lt;BR /&gt;
I also believe the lookahead is unnecessary.  You could just do &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(tstp \d (?P&amp;lt;tstp_date&amp;gt;\S+) (?P&amp;lt;tstp_time&amp;gt;\S+))?
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If tstp is not present, the clause won't match.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Nov 2014 15:44:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-I-provide-a-default-value-for-a-rex-command-field-extraction/m-p/122203#M32900</guid>
      <dc:creator>jrodman</dc:creator>
      <dc:date>2014-11-14T15:44:32Z</dc:date>
    </item>
    <item>
      <title>Re: Can I provide a default value for a |rex command field extraction?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-I-provide-a-default-value-for-a-rex-command-field-extraction/m-p/122204#M32901</link>
      <description>&lt;P&gt;Agree jrodman - your suggestion is cleaner than what I was proposing. Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Nov 2014 09:05:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-I-provide-a-default-value-for-a-rex-command-field-extraction/m-p/122204#M32901</guid>
      <dc:creator>splunkhelp</dc:creator>
      <dc:date>2014-11-17T09:05:50Z</dc:date>
    </item>
  </channel>
</rss>

