<?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: rex field not visible and cannot be used in eval in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/rex-field-not-visible-and-cannot-be-used-in-eval/m-p/288975#M165062</link>
    <description>&lt;P&gt;I'm assuming that the second line looks something like this?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | rex "#TAGRESPONSE.*RESPONSETYPE\:(?&amp;lt;RESPONSETYPE&amp;gt;.+?)LICENSESTATE" 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;...and that the underlying _raw data looks something like this...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;some stuff #TAGRESPONSE:foobar more stuff  RESPONSETYPE:someresponsetype LICENSESTATE:something else
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If so, then what is happening is that your rex is picking up the space after responsetype and before licensestate, and that this code would work (but there's a better way)... &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;'RESPONSETYPE'=="ER51 "  
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;(notice the space after ER51?)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | rex "#TAGRESPONSE.*RESPONSETYPE\:(?&amp;lt;RESPONSETYPE&amp;gt;\S+)\s+LICENSESTATE" 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This assumes that a responsetype cannot include any spaces.  By narrowly typing the responsetype as "things that aren't whitespace (\S) you don't have to make it lazy, it will quit when it gets to the first whitespace, and not include that in the responsecode it is collecting for you. &lt;/P&gt;

&lt;P&gt;On the other hand, if the responsecode CAN include spaces, then you do it this way...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | rex "#TAGRESPONSE.*RESPONSETYPE\:(?&amp;lt;RESPONSETYPE&amp;gt;.+?)\s*LICENSESTATE" 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 17 Nov 2017 15:03:43 GMT</pubDate>
    <dc:creator>DalJeanis</dc:creator>
    <dc:date>2017-11-17T15:03:43Z</dc:date>
    <item>
      <title>rex field not visible and cannot be used in eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-field-not-visible-and-cannot-be-used-in-eval/m-p/288973#M165060</link>
      <description>&lt;P&gt;Hi I have this query and trying to do a eval case on the rex field value returned&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;base
| rex "#TAGRESPONSE.*RESPONSETYPE\:(?.+?)LICENSESTATE" 
| eval code=case('RESPONSETYPE'=="ER51","BATCH", 'RESPONSETYPE'=="ER91","NON-BATCH")
| stats count by code
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Its not working, as it cannot see the extracted field RESPONSETYPE.&lt;BR /&gt;
But when i do stats count by RESPONSETYPE, it works just fine.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 14:32:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-field-not-visible-and-cannot-be-used-in-eval/m-p/288973#M165060</guid>
      <dc:creator>maniishpawar</dc:creator>
      <dc:date>2017-11-17T14:32:43Z</dc:date>
    </item>
    <item>
      <title>Re: rex field not visible and cannot be used in eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-field-not-visible-and-cannot-be-used-in-eval/m-p/288974#M165061</link>
      <description>&lt;P&gt;We've marked your code as code, so that HTML-like attributes will not be deleted by the interface.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 14:50:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-field-not-visible-and-cannot-be-used-in-eval/m-p/288974#M165061</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-11-17T14:50:59Z</dc:date>
    </item>
    <item>
      <title>Re: rex field not visible and cannot be used in eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-field-not-visible-and-cannot-be-used-in-eval/m-p/288975#M165062</link>
      <description>&lt;P&gt;I'm assuming that the second line looks something like this?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | rex "#TAGRESPONSE.*RESPONSETYPE\:(?&amp;lt;RESPONSETYPE&amp;gt;.+?)LICENSESTATE" 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;...and that the underlying _raw data looks something like this...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;some stuff #TAGRESPONSE:foobar more stuff  RESPONSETYPE:someresponsetype LICENSESTATE:something else
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If so, then what is happening is that your rex is picking up the space after responsetype and before licensestate, and that this code would work (but there's a better way)... &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;'RESPONSETYPE'=="ER51 "  
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;(notice the space after ER51?)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | rex "#TAGRESPONSE.*RESPONSETYPE\:(?&amp;lt;RESPONSETYPE&amp;gt;\S+)\s+LICENSESTATE" 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This assumes that a responsetype cannot include any spaces.  By narrowly typing the responsetype as "things that aren't whitespace (\S) you don't have to make it lazy, it will quit when it gets to the first whitespace, and not include that in the responsecode it is collecting for you. &lt;/P&gt;

&lt;P&gt;On the other hand, if the responsecode CAN include spaces, then you do it this way...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | rex "#TAGRESPONSE.*RESPONSETYPE\:(?&amp;lt;RESPONSETYPE&amp;gt;.+?)\s*LICENSESTATE" 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Nov 2017 15:03:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-field-not-visible-and-cannot-be-used-in-eval/m-p/288975#M165062</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-11-17T15:03:43Z</dc:date>
    </item>
    <item>
      <title>Re: rex field not visible and cannot be used in eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-field-not-visible-and-cannot-be-used-in-eval/m-p/288976#M165063</link>
      <description>&lt;P&gt;here is the actual data.&lt;BR /&gt;
REQUESTTIME: 2017-11-17 09:28:29 RESPONSETIME: 2017-11-17 09:28:29 RETURNCODE:  RATEFOR: CIFG BUSINESSFUNCTION: NBS &lt;/P&gt;

&lt;P&gt;REQUESTTIME: 2017-11-17 09:28:29 RESPONSETIME: 2017-11-17 09:28:29 RETURNCODE: 9852 RATEFOR: CIFG BUSINESSFUNCTION: NBS&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 15:16:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-field-not-visible-and-cannot-be-used-in-eval/m-p/288976#M165063</guid>
      <dc:creator>maniishpawar</dc:creator>
      <dc:date>2017-11-17T15:16:15Z</dc:date>
    </item>
    <item>
      <title>Re: rex field not visible and cannot be used in eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-field-not-visible-and-cannot-be-used-in-eval/m-p/288977#M165064</link>
      <description>&lt;P&gt;Also I tried to use empty space at the beginning and at trailing of ER51 code, it didnt work in any of those scenarios.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 15:17:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-field-not-visible-and-cannot-be-used-in-eval/m-p/288977#M165064</guid>
      <dc:creator>maniishpawar</dc:creator>
      <dc:date>2017-11-17T15:17:11Z</dc:date>
    </item>
    <item>
      <title>Re: rex field not visible and cannot be used in eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-field-not-visible-and-cannot-be-used-in-eval/m-p/288978#M165065</link>
      <description>&lt;P&gt;oh and you can use RETURNCODE for regex, earlier i have given a dummy field name to post question.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 15:21:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-field-not-visible-and-cannot-be-used-in-eval/m-p/288978#M165065</guid>
      <dc:creator>maniishpawar</dc:creator>
      <dc:date>2017-11-17T15:21:15Z</dc:date>
    </item>
    <item>
      <title>Re: rex field not visible and cannot be used in eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-field-not-visible-and-cannot-be-used-in-eval/m-p/288979#M165066</link>
      <description>&lt;P&gt;its weird, this time I tried space both trailing and leading and it worked. so i used trim and trim worked.&lt;BR /&gt;
but why rex is adding spaces to the value retrieved ?&lt;BR /&gt;
what should i change in rex to avoid the space, as if i have 5-10 fields extracted, each will have the trailing and leading space to their values&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 17:39:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-field-not-visible-and-cannot-be-used-in-eval/m-p/288979#M165066</guid>
      <dc:creator>maniishpawar</dc:creator>
      <dc:date>2017-11-17T17:39:01Z</dc:date>
    </item>
    <item>
      <title>Re: rex field not visible and cannot be used in eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/rex-field-not-visible-and-cannot-be-used-in-eval/m-p/288980#M165067</link>
      <description>&lt;P&gt;You have to account for possible trailing spaces in the rex, otherwise if they exist in the source data they will be captured. If you know they the spaces are always in the source data you can write:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex "#TAGRESPONSE.*?RESPONSETYPE\:(?&amp;lt;RESPONSETYPE&amp;gt;[^\s]+)\s+?LICENSESTATE"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But if you want account for the spaces possibly being there but account for the possibility that they won't?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex "#TAGRESPONSE.*?RESPONSETYPE\:\s*?(?&amp;lt;RESPONSETYPE&amp;gt;.*?)\s*?LICENSESTATE"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The first regex is less computationally expensive but won't capture fields that unless they are formatted properly.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2017 18:28:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/rex-field-not-visible-and-cannot-be-used-in-eval/m-p/288980#M165067</guid>
      <dc:creator>wenthold</dc:creator>
      <dc:date>2017-11-17T18:28:06Z</dc:date>
    </item>
  </channel>
</rss>

