<?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: Erex example in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Erex-example/m-p/294921#M164870</link>
    <description>&lt;P&gt;Thanks for your clear explanation. It is very useful. &lt;/P&gt;</description>
    <pubDate>Wed, 29 Nov 2017 13:44:18 GMT</pubDate>
    <dc:creator>amarish_vlabs</dc:creator>
    <dc:date>2017-11-29T13:44:18Z</dc:date>
    <item>
      <title>Erex example</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Erex-example/m-p/294916#M164865</link>
      <description>&lt;P&gt;Hi, I have the below log  and  values for  "days" field  are 4, 10 , 15, 30.  Could you please extract the "days"  field using the "erex"  command.  &lt;/P&gt;

&lt;P&gt;Log :    &lt;/P&gt;

&lt;P&gt;2017-11-21 04:55:34,060 tn="[14347886-7337]" ll=INFO cn="s.c.m" - id="57ef4442-aa9f-444d-bd80-e4fd3018f82",  action="execute", operation="put", collection="Messages", "days" : "4", "Code" : "491833",  useSecondary="false", retries="0"&lt;/P&gt;</description>
      <pubDate>Thu, 23 Nov 2017 15:07:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Erex-example/m-p/294916#M164865</guid>
      <dc:creator>amarish_vlabs</dc:creator>
      <dc:date>2017-11-23T15:07:50Z</dc:date>
    </item>
    <item>
      <title>Re: Erex example</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Erex-example/m-p/294917#M164866</link>
      <description>&lt;P&gt;Hi &lt;/P&gt;

&lt;P&gt;Can you please try this configuration?&lt;/P&gt;

&lt;P&gt;props.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[my_sourcetype]
REPORT-mydays = mydays
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;transforms.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[mydays]
REGEX = \"days\"\s:\s\"(?&amp;lt;days&amp;gt;.+)\",\s\"
FORMAT = $1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 23 Nov 2017 16:55:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Erex-example/m-p/294917#M164866</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2017-11-23T16:55:09Z</dc:date>
    </item>
    <item>
      <title>Re: Erex example</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Erex-example/m-p/294918#M164867</link>
      <description>&lt;P&gt;@amarish_vlabs, any reason why you want to rely on &lt;CODE&gt;erex&lt;/CODE&gt; and not &lt;CODE&gt;rex&lt;/CODE&gt; or regular expression?&lt;/P&gt;</description>
      <pubDate>Thu, 23 Nov 2017 17:01:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Erex-example/m-p/294918#M164867</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-11-23T17:01:09Z</dc:date>
    </item>
    <item>
      <title>Re: Erex example</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Erex-example/m-p/294919#M164868</link>
      <description>&lt;P&gt;Following is a run anywhere search example for &lt;CODE&gt;erex&lt;/CODE&gt; command to extract the field you are interested in  (based on the sample provided). Please try out and confirm.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|  makeresults
|  eval _raw="2017-11-21 04:55:34,060 tn=\"[14347886-7337]\" ll=INFO cn=\"s.c.m\" - id=\"57ef4442-aa9f-444d-bd80-e4fd3018f82\", action=\"execute\", operation=\"put\", collection=\"Messages\", \"days\" : \"4\", \"Code\" : \"491833\", useSecondary=\"false\", retries=\"0\""
|  append
    [|  makeresults
    |  eval _raw="2017-11-21 04:56:34,060 tn=\"[14347886-7337]\" ll=INFO cn=\"s.c.m\" - id=\"57ef4442-aa9f-444d-bd80-e4fd3018f83\", action=\"execute\", operation=\"put\", collection=\"Messages\", \"days\" : \"13\", \"Code\" : \"491834\", useSecondary=\"false\", retries=\"0\""]
|  append
    [|  makeresults
    |  eval _raw="2017-11-21 04:57:34,060 tn=\"[14347886-7337]\" ll=INFO cn=\"s.c.m\" - id=\"57ef4442-aa9f-444d-bd80-e4fd3018f84\", action=\"execute\", operation=\"put\", collection=\"Messages\", \"days\" : \"24\", \"Code\" : \"491835\", useSecondary=\"false\", retries=\"0\""]
|  append
    [|  makeresults
    |  eval _raw="2017-11-21 04:58:34,060 tn=\"[14347886-7337]\" ll=INFO cn=\"s.c.m\" - id=\"57ef4442-aa9f-444d-bd80-e4fd3018f85\", action=\"execute\", operation=\"put\", collection=\"Messages\", \"days\" : \"14\", \"Code\" : \"491836\", useSecondary=\"false\", retries=\"0\""]
|  erex days examples="4,13"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Ideally you should use &lt;CODE&gt;rex&lt;/CODE&gt; command and once you have tested the same save your regular expression as &lt;CODE&gt;Field Extraction&lt;/CODE&gt; for reusability and maintenance. Following is the regular expression:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|  makeresults
|  eval _raw="2017-11-21 04:55:34,060 tn=\"[14347886-7337]\" ll=INFO cn=\"s.c.m\" - id=\"57ef4442-aa9f-444d-bd80-e4fd3018f82\", action=\"execute\", operation=\"put\", collection=\"Messages\", \"days\" : \"4\", \"Code\" : \"491833\", useSecondary=\"false\", retries=\"0\""
|  append
    [|  makeresults
    |  eval _raw="2017-11-21 04:56:34,060 tn=\"[14347886-7337]\" ll=INFO cn=\"s.c.m\" - id=\"57ef4442-aa9f-444d-bd80-e4fd3018f83\", action=\"execute\", operation=\"put\", collection=\"Messages\", \"days\" : \"13\", \"Code\" : \"491834\", useSecondary=\"false\", retries=\"0\""]
|  append
    [|  makeresults
    |  eval _raw="2017-11-21 04:57:34,060 tn=\"[14347886-7337]\" ll=INFO cn=\"s.c.m\" - id=\"57ef4442-aa9f-444d-bd80-e4fd3018f84\", action=\"execute\", operation=\"put\", collection=\"Messages\", \"days\" : \"24\", \"Code\" : \"491835\", useSecondary=\"false\", retries=\"0\""]
|  append
    [|  makeresults
    |  eval _raw="2017-11-21 04:58:34,060 tn=\"[14347886-7337]\" ll=INFO cn=\"s.c.m\" - id=\"57ef4442-aa9f-444d-bd80-e4fd3018f85\", action=\"execute\", operation=\"put\", collection=\"Messages\", \"days\" : \"14\", \"Code\" : \"491836\", useSecondary=\"false\", retries=\"0\""]
|  rex "\"days\"\s+:\s+\"(?&amp;lt;days&amp;gt;[^\"]+)\""
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;While the above examples use &lt;CODE&gt;makeresults&lt;/CODE&gt; and &lt;CODE&gt;append&lt;/CODE&gt; to mock some sample events as per question. You can try out the final pipe with &lt;CODE&gt;erex&lt;/CODE&gt; or &lt;CODE&gt;rex&lt;/CODE&gt; in your base search returning data as per your question:&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Using rex command&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;YourBaseSearch&amp;gt;
|  rex "\"days\"\s+:\s+\"(?&amp;lt;days&amp;gt;[^\"]+)\""
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Using erex command&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;YourBaseSearch&amp;gt;
|  erex days examples="4,13"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS: &lt;CODE&gt;erex might not be robust for field extraction in production data or else you will have to use a lot of sample examples and counterexamples.&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Nov 2017 17:14:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Erex-example/m-p/294919#M164868</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-11-23T17:14:33Z</dc:date>
    </item>
    <item>
      <title>Re: Erex example</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Erex-example/m-p/294920#M164869</link>
      <description>&lt;P&gt;@niketnilay,  I extracted the days field by using  "rex"  command.  I just want to know how to extract with "erex".    If this is possible with "erex", Please let me know.  Otherwise  just ignore.  Thank you sir for your reply.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 13:42:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Erex-example/m-p/294920#M164869</guid>
      <dc:creator>amarish_vlabs</dc:creator>
      <dc:date>2017-11-29T13:42:58Z</dc:date>
    </item>
    <item>
      <title>Re: Erex example</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Erex-example/m-p/294921#M164870</link>
      <description>&lt;P&gt;Thanks for your clear explanation. It is very useful. &lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 13:44:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Erex-example/m-p/294921#M164870</guid>
      <dc:creator>amarish_vlabs</dc:creator>
      <dc:date>2017-11-29T13:44:18Z</dc:date>
    </item>
    <item>
      <title>Re: Erex example</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Erex-example/m-p/294922#M164871</link>
      <description>&lt;P&gt;Thank you so much for your reply.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 13:44:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Erex-example/m-p/294922#M164871</guid>
      <dc:creator>amarish_vlabs</dc:creator>
      <dc:date>2017-11-29T13:44:48Z</dc:date>
    </item>
    <item>
      <title>Re: Erex example</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Erex-example/m-p/294923#M164872</link>
      <description>&lt;P&gt;@amarish_vlabs, glad you found it useful. Please accept/up vote the answer if it helped &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 14:37:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Erex-example/m-p/294923#M164872</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-11-29T14:37:25Z</dc:date>
    </item>
    <item>
      <title>Re: Erex example</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Erex-example/m-p/294924#M164873</link>
      <description>&lt;P&gt;@amarish_vlabs, Here is your sample Event : &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;2017-11-21 04:55:34,060 tn="[14347886-7337]" ll=INFO cn="s.c.m" - id="57ef4442-aa9f-444d-bd80-e4fd3018f82", action="execute", operation="put", collection="Messages", "days" : "4", "Code" : "491833", useSecondary="false", retries="0"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;using erex: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=* source="amarish_vlabs.txt"  | erex newfield_days examples=4
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Job says : &lt;CODE&gt;Successfully learned regex. Consider using: | rex "(?i)\-e(?P&amp;lt;newfield_days&amp;gt;\d+)"&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Now we can see &lt;STRONG&gt;new Search-time field&lt;/STRONG&gt; "&lt;CODE&gt;newfield_days&lt;/CODE&gt;" has been extracted &lt;STRONG&gt;on-the-fly&lt;/STRONG&gt;  &lt;EM&gt;(not persistent field)&lt;/EM&gt; and moving forward better we use the rex command as that's efficient &amp;amp; faster. &lt;BR /&gt;
Using rex : &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=* source="amarish_vlabs.txt"  | rex "(?i)\-e(?P&amp;lt;newfield_days&amp;gt;\d+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This answer is to start rolling the ball based on one given event. To generalize this on larger set of data and generate (possibly) precise regular expression using &lt;CODE&gt;erex&lt;/CODE&gt; command, use the optional arguments like counterexamples, fromfield &amp;amp; maxtrainers. &lt;/P&gt;

&lt;P&gt;here is syntax of erex : &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;erex [&amp;lt;field&amp;gt;] examples=&amp;lt;string&amp;gt; [counterexamples=&amp;lt;string&amp;gt;] [fromfield=&amp;lt;field&amp;gt;] [maxtrainers=&amp;lt;int&amp;gt;]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You may see more examples &lt;A href="http://docs.splunk.com/Documentation/SplunkCloud/6.6.3/SearchReference/Erex"&gt;here&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Dec 2017 06:12:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Erex-example/m-p/294924#M164873</guid>
      <dc:creator>saurabh_tek11</dc:creator>
      <dc:date>2017-12-06T06:12:15Z</dc:date>
    </item>
    <item>
      <title>Re: Erex example</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Erex-example/m-p/294925#M164874</link>
      <description>&lt;P&gt;Hi @amarish_vlabs, does this answers your question or you have some query? Please feel free to ask.&lt;BR /&gt;
If no query, please accept the answer so as to close this open question.  &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Thank you - Saurabh&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2017 12:21:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Erex-example/m-p/294925#M164874</guid>
      <dc:creator>saurabh_tek11</dc:creator>
      <dc:date>2017-12-20T12:21:36Z</dc:date>
    </item>
  </channel>
</rss>

