<?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: How to insert IF in regular expression in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-insert-IF-in-regular-expression/m-p/347580#M102947</link>
    <description>&lt;P&gt;Is Splunk not extracting them for you automatically? can we have some sample events which contains field1 and field2 ?&lt;/P&gt;

&lt;P&gt;A simpler option would be to just setup two field extractions, one for field1 and one for field2. For events where field2 is not there, it won't extract anything anyways (null value).&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[yoursourcetype]
 EXTRACT-field1= field1=(?&amp;lt;field1&amp;gt;\w+)
 EXTRACT-field2= field2=(?&amp;lt;field2&amp;gt;\w+)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 27 Apr 2017 14:23:13 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2017-04-27T14:23:13Z</dc:date>
    <item>
      <title>How to insert IF in regular expression</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-insert-IF-in-regular-expression/m-p/347577#M102944</link>
      <description>&lt;P&gt;Hi to all, I should extract some fields by a log file, in the log file in some cases I have a field (i.e. field1, in other cases I have another field (i.e. field2).&lt;/P&gt;

&lt;P&gt;For example the log file can contain field1=value1 or field2=value2&lt;/P&gt;

&lt;P&gt;I need to do something like &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;IF log contains filed1 
EXTRACT- field1 =.*field1=(?P&amp;lt;field1&amp;gt;\w+).*
ELSE
EXTRACT- field2 =.*field2=(?P&amp;lt;field2&amp;gt;\w+).*
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Is it possible?&lt;BR /&gt;
Thanks,&lt;BR /&gt;
Andrea&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2017 21:03:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-insert-IF-in-regular-expression/m-p/347577#M102944</guid>
      <dc:creator>andreac81</dc:creator>
      <dc:date>2017-04-26T21:03:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert IF in regular expression</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-insert-IF-in-regular-expression/m-p/347578#M102945</link>
      <description>&lt;P&gt;The values seems to be standard key-value pair with equal sign as delimiter. Is Splunk not extracting them automatically for you (try to run the search in Smart Mode)?&lt;/P&gt;

&lt;P&gt;Also, an event will contain either of field1 or field2, so do you want to extract them as separate field name (field1 or field2) or just a common name (say fieldname) so that you can correlate them? If you can use a common name, try like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[yoursourcetype]
EXTRACT-fieldname = (field1|field2)=(?&amp;lt;fieldname&amp;gt;\w+)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Apr 2017 21:38:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-insert-IF-in-regular-expression/m-p/347578#M102945</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-04-26T21:38:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert IF in regular expression</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-insert-IF-in-regular-expression/m-p/347579#M102946</link>
      <description>&lt;P&gt;Using &lt;BR /&gt;
     EXTRACT-fieldname = (field1|field2)=(?&lt;FIELDNAME&gt;\w+)&lt;BR /&gt;
I store both field1 or field2 in fieldname, I need to store field1 in fieldname1 and field2 in fieldname2 considering that the log file can contains sometimes field1 other times field2&lt;/FIELDNAME&gt;&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 27 Apr 2017 14:15:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-insert-IF-in-regular-expression/m-p/347579#M102946</guid>
      <dc:creator>andreac81</dc:creator>
      <dc:date>2017-04-27T14:15:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert IF in regular expression</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-insert-IF-in-regular-expression/m-p/347580#M102947</link>
      <description>&lt;P&gt;Is Splunk not extracting them for you automatically? can we have some sample events which contains field1 and field2 ?&lt;/P&gt;

&lt;P&gt;A simpler option would be to just setup two field extractions, one for field1 and one for field2. For events where field2 is not there, it won't extract anything anyways (null value).&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[yoursourcetype]
 EXTRACT-field1= field1=(?&amp;lt;field1&amp;gt;\w+)
 EXTRACT-field2= field2=(?&amp;lt;field2&amp;gt;\w+)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Apr 2017 14:23:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-insert-IF-in-regular-expression/m-p/347580#M102947</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-04-27T14:23:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert IF in regular expression</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-insert-IF-in-regular-expression/m-p/347581#M102948</link>
      <description>&lt;P&gt;Hi there, perhaps something like this might work for you.&lt;/P&gt;

&lt;P&gt;In &lt;CODE&gt;props.conf&lt;/CODE&gt; add this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[&amp;lt;your_sourcetype&amp;gt;]
TRANSFORMS-kv_xtraction = kv_extraction
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In &lt;CODE&gt;transforms.conf&lt;/CODE&gt; add this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[kv_extraction]
REGEX = \s([^\s]+)=([^\s]+)
FORMAT = $1::$2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope it helps.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Apr 2017 15:40:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-insert-IF-in-regular-expression/m-p/347581#M102948</guid>
      <dc:creator>alemarzu</dc:creator>
      <dc:date>2017-04-27T15:40:13Z</dc:date>
    </item>
  </channel>
</rss>

