<?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: Conditional Rex Expression in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Conditional-Rex-Expression/m-p/123893#M33469</link>
    <description>&lt;PRE&gt;&lt;CODE&gt;| rex "Employers Name=(?&amp;lt;employersname&amp;gt;[^,]*)" | rex "Providers Name=(?&amp;lt;providername&amp;gt;[^,]*)" | eval contactname=coalesce(employersname,providername) | table contactname
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This should extract both the Employer's Name (if it exists) and the Provider's Name (if it exists) and fill the field "contactname" with the employers name, unless that's empty, then it'll put the providername in there.&lt;/P&gt;

&lt;P&gt;I see from your logging that it's all key/value pairs, did you try using the &lt;CODE&gt;| extract pairdelim=",", kvdelim="="&lt;/CODE&gt; keyword to automatically extract these fields? Splunk will extract the Employer's Name and Provider's Name if they exist and that should solve all your problems.&lt;/P&gt;</description>
    <pubDate>Wed, 15 Jul 2015 15:33:35 GMT</pubDate>
    <dc:creator>lcrielaa</dc:creator>
    <dc:date>2015-07-15T15:33:35Z</dc:date>
    <item>
      <title>Conditional Rex Expression</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-Rex-Expression/m-p/123888#M33464</link>
      <description>&lt;P&gt;Hi, I wonder whether someone could help me please.&lt;/P&gt;

&lt;P&gt;I'm using the following rex expression to extract the Employers Name : &lt;CODE&gt;rex "Employers Name=(?&amp;amp;lt;contactname&amp;amp;gt;[^,]*)".&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;I then have the following rex expression to extract the Providers Name: &lt;CODE&gt;rex "Providers Name=(?&amp;amp;lt;contactname&amp;amp;gt;[^,]*)".&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;I'm not even sure whether this is possible, but could someone tell me please is there a way by which I can join these, so if the 'Employers Name' is shown in the event data then that is the data used for the 'contactname' value, but if the 'Providers Name' is present, then use this value for the 'contactname' field.&lt;/P&gt;

&lt;P&gt;Many thanks and kind regards&lt;/P&gt;

&lt;P&gt;Chris&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jul 2015 11:18:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-Rex-Expression/m-p/123888#M33464</guid>
      <dc:creator>IRHM73</dc:creator>
      <dc:date>2015-07-15T11:18:19Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Rex Expression</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-Rex-Expression/m-p/123889#M33465</link>
      <description>&lt;P&gt;There's the eval command called "coalesce" which merges two fields together into a new field. Imagine the following; I have 2 fields that contains values, these fields are called "clientip" and "ipaddress", but sometimes "clientip" is empty and then I want to use the value from "ipaddress" instead. What I do is I coalesce these two fields together into a new field called "IpAddr".&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval IpAddr=coalesce(clientip, ipaddress)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The field "IpAddr" will be filled with the value from "clientip", unless "clientip" is empty, then it'll pick the value from "ipaddress". You can add as many fields to coalesce as you want.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jul 2015 12:17:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-Rex-Expression/m-p/123889#M33465</guid>
      <dc:creator>lcrielaa</dc:creator>
      <dc:date>2015-07-15T12:17:08Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Rex Expression</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-Rex-Expression/m-p/123890#M33466</link>
      <description>&lt;P&gt;Hi @Icrielaa, thank you for taking the time to read my post and come back to me with this.&lt;/P&gt;

&lt;P&gt;With your kind suggestion, I've put together the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval contact=coalesce(Employers_Name, Provider_Name)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The problem I have is that where a 'Provider Name' is found, it using the value 'Provide Name' rather than the field value.&lt;/P&gt;

&lt;P&gt;Many thanks and kind regards&lt;/P&gt;

&lt;P&gt;Chris&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jul 2015 12:42:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-Rex-Expression/m-p/123890#M33466</guid>
      <dc:creator>IRHM73</dc:creator>
      <dc:date>2015-07-15T12:42:53Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Rex Expression</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-Rex-Expression/m-p/123891#M33467</link>
      <description>&lt;P&gt;do you have some sample logging that you could post here (just a few lines)?&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jul 2015 13:03:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-Rex-Expression/m-p/123891#M33467</guid>
      <dc:creator>lcrielaa</dc:creator>
      <dc:date>2015-07-15T13:03:21Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Rex Expression</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-Rex-Expression/m-p/123892#M33468</link>
      <description>&lt;P&gt;Hi, thank you for coming back to me with this.&lt;/P&gt;

&lt;P&gt;Because of it's convidential nature I can only provide some examples as below. I hope this is ok?&lt;/P&gt;

&lt;P&gt;I had a thought though, I'm just wondering whether the problem could be because of two issues:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;Either the field 'Employer Name' or 'Provider Name' are present, but the field is blank,&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;Neither the fields 'Employer Name' or 'Provider Name' are present. &lt;/P&gt;

&lt;P&gt;Employers Name=The Employer, Employers Address=Address Line 1=The Road, Address Line 2=The Town, Address Line 3=, Address Line 4=, Employers PostCode=AB1 2CD"&lt;/P&gt;

&lt;P&gt;Providers Name=The Employer, Employers Address=Address Line 1=The Road, Address Line 2=The Town, Address Line 3=, Address Line 4=, Employers PostCode=AB1 2CD"&lt;/P&gt;&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;Many thanks and kind regards&lt;/P&gt;

&lt;P&gt;Chris&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jul 2015 13:34:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-Rex-Expression/m-p/123892#M33468</guid>
      <dc:creator>IRHM73</dc:creator>
      <dc:date>2015-07-15T13:34:03Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Rex Expression</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-Rex-Expression/m-p/123893#M33469</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;| rex "Employers Name=(?&amp;lt;employersname&amp;gt;[^,]*)" | rex "Providers Name=(?&amp;lt;providername&amp;gt;[^,]*)" | eval contactname=coalesce(employersname,providername) | table contactname
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This should extract both the Employer's Name (if it exists) and the Provider's Name (if it exists) and fill the field "contactname" with the employers name, unless that's empty, then it'll put the providername in there.&lt;/P&gt;

&lt;P&gt;I see from your logging that it's all key/value pairs, did you try using the &lt;CODE&gt;| extract pairdelim=",", kvdelim="="&lt;/CODE&gt; keyword to automatically extract these fields? Splunk will extract the Employer's Name and Provider's Name if they exist and that should solve all your problems.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jul 2015 15:33:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-Rex-Expression/m-p/123893#M33469</guid>
      <dc:creator>lcrielaa</dc:creator>
      <dc:date>2015-07-15T15:33:35Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Rex Expression</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Conditional-Rex-Expression/m-p/123894#M33470</link>
      <description>&lt;P&gt;Thank you @Icrielaa, your code worked great.&lt;/P&gt;

&lt;P&gt;Many thanks and kind regards&lt;/P&gt;

&lt;P&gt;Chris&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jul 2015 07:41:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Conditional-Rex-Expression/m-p/123894#M33470</guid>
      <dc:creator>IRHM73</dc:creator>
      <dc:date>2015-07-20T07:41:20Z</dc:date>
    </item>
  </channel>
</rss>

