<?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 How do I get a certain rex field extraction to run if a field equals a specific value? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-get-a-certain-rex-field-extraction-to-run-if-a-field/m-p/260231#M78007</link>
    <description>&lt;P&gt;Hi, &lt;/P&gt;

&lt;P&gt;Firstly, I'm not sure whether this is even possible, but I wonder whether someone may be able to help me please.&lt;/P&gt;

&lt;P&gt;I've put together the following search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  index=main auditSource=contact-frontend auditType=ServiceReceivedRequest detail.referrer!="-" OR detail.requestBody!=""  
    |rex field="detail.requestBody" "(?&amp;lt;selectservice&amp;gt;[^\=]+)"
    |rex field="detail.requestBody" "error=(?&amp;lt;servicecomments&amp;gt;[^\=]+)"
    |eval servicecomments=replace(servicecomments, "\+", " ") 
    |rex field="detail.requestBody" "error=(?&amp;lt;reportcomments&amp;gt;[^$]+)\&amp;amp;is"
    |eval reportcomments=replace(reportcomments, "\+", " ")
    |rex field="detail.requestBody" "action=(?&amp;lt;csrfcomments&amp;gt;[^$]+)\&amp;amp;is"
    |eval csrfcomments=replace(csrfcomments, "\+", " ")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In its current form, there are three fields which extract comments. These are &lt;STRONG&gt;servicecomments&lt;/STRONG&gt;, &lt;STRONG&gt;reportcomments&lt;/STRONG&gt; and &lt;STRONG&gt;csrfcomments&lt;/STRONG&gt; which are three separate fields in my results table.&lt;/P&gt;

&lt;P&gt;What I'd like to do is amalgamate the comments fields to one, but then have an 'if statement' so if the "selectservice" field &lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;equals "service", then it extracts "servicecomments", &lt;/LI&gt;
&lt;LI&gt;equals "report-name" then extract "reportcomments"&lt;/LI&gt;
&lt;LI&gt;equals "csrf" extract "csrfcomments".&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;This then means that the comments would appear in one field rather than three separate ones.&lt;/P&gt;

&lt;P&gt;I did try the following to test two of the fields, but it didn't work.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; |eval comments=if(selectservice="csrfToken",csrfcomments,servicecomments)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I just wondered whether someone may be able to look at this please and offer some guidance on how I may achieve this.&lt;/P&gt;

&lt;P&gt;Many thanks and kind regards&lt;/P&gt;

&lt;P&gt;Chris&lt;/P&gt;</description>
    <pubDate>Tue, 02 Feb 2016 08:20:40 GMT</pubDate>
    <dc:creator>IRHM73</dc:creator>
    <dc:date>2016-02-02T08:20:40Z</dc:date>
    <item>
      <title>How do I get a certain rex field extraction to run if a field equals a specific value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-get-a-certain-rex-field-extraction-to-run-if-a-field/m-p/260231#M78007</link>
      <description>&lt;P&gt;Hi, &lt;/P&gt;

&lt;P&gt;Firstly, I'm not sure whether this is even possible, but I wonder whether someone may be able to help me please.&lt;/P&gt;

&lt;P&gt;I've put together the following search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  index=main auditSource=contact-frontend auditType=ServiceReceivedRequest detail.referrer!="-" OR detail.requestBody!=""  
    |rex field="detail.requestBody" "(?&amp;lt;selectservice&amp;gt;[^\=]+)"
    |rex field="detail.requestBody" "error=(?&amp;lt;servicecomments&amp;gt;[^\=]+)"
    |eval servicecomments=replace(servicecomments, "\+", " ") 
    |rex field="detail.requestBody" "error=(?&amp;lt;reportcomments&amp;gt;[^$]+)\&amp;amp;is"
    |eval reportcomments=replace(reportcomments, "\+", " ")
    |rex field="detail.requestBody" "action=(?&amp;lt;csrfcomments&amp;gt;[^$]+)\&amp;amp;is"
    |eval csrfcomments=replace(csrfcomments, "\+", " ")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In its current form, there are three fields which extract comments. These are &lt;STRONG&gt;servicecomments&lt;/STRONG&gt;, &lt;STRONG&gt;reportcomments&lt;/STRONG&gt; and &lt;STRONG&gt;csrfcomments&lt;/STRONG&gt; which are three separate fields in my results table.&lt;/P&gt;

&lt;P&gt;What I'd like to do is amalgamate the comments fields to one, but then have an 'if statement' so if the "selectservice" field &lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;equals "service", then it extracts "servicecomments", &lt;/LI&gt;
&lt;LI&gt;equals "report-name" then extract "reportcomments"&lt;/LI&gt;
&lt;LI&gt;equals "csrf" extract "csrfcomments".&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;This then means that the comments would appear in one field rather than three separate ones.&lt;/P&gt;

&lt;P&gt;I did try the following to test two of the fields, but it didn't work.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; |eval comments=if(selectservice="csrfToken",csrfcomments,servicecomments)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I just wondered whether someone may be able to look at this please and offer some guidance on how I may achieve this.&lt;/P&gt;

&lt;P&gt;Many thanks and kind regards&lt;/P&gt;

&lt;P&gt;Chris&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2016 08:20:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-get-a-certain-rex-field-extraction-to-run-if-a-field/m-p/260231#M78007</guid>
      <dc:creator>IRHM73</dc:creator>
      <dc:date>2016-02-02T08:20:40Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get a certain rex field extraction to run if a field equals a specific value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-get-a-certain-rex-field-extraction-to-run-if-a-field/m-p/260232#M78008</link>
      <description>&lt;P&gt;This is what I would do:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval comments = case (
    selectservice == "service", servicecomments,
    selectservice == "report-name", reportcomments,
    selectservice == "csrf", csrfcomments
)
| fields - servicecomments, reportcomments, csrfcomments
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope that helps&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2016 09:30:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-get-a-certain-rex-field-extraction-to-run-if-a-field/m-p/260232#M78008</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-02-02T09:30:52Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get a certain rex field extraction to run if a field equals a specific value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-get-a-certain-rex-field-extraction-to-run-if-a-field/m-p/260233#M78009</link>
      <description>&lt;P&gt;Hi @javiergn, thank you very much for taking the time to help me with this.&lt;/P&gt;

&lt;P&gt;The solution works great!&lt;/P&gt;

&lt;P&gt;Kind Regards&lt;/P&gt;

&lt;P&gt;Chris&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2016 09:46:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-get-a-certain-rex-field-extraction-to-run-if-a-field/m-p/260233#M78009</guid>
      <dc:creator>IRHM73</dc:creator>
      <dc:date>2016-02-02T09:46:25Z</dc:date>
    </item>
  </channel>
</rss>

