<?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: Eval Match function Issue in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Eval-Match-function-Issue/m-p/306928#M92066</link>
    <description>&lt;P&gt;Based on your description Date can be 6 digits (YYMMDD) or 8 digits (YYYYMMDD). Which is followed by &lt;CODE&gt;._D&lt;/CODE&gt; in the filename.&lt;BR /&gt;
I expect your existing logic to fail when you have two 20s or two 17s in the date like &lt;STRONG&gt;20170220&lt;/STRONG&gt; or &lt;STRONG&gt;170117&lt;/STRONG&gt; etc. &lt;/P&gt;

&lt;P&gt;One of the ways would be to match &lt;CODE&gt;^20&lt;/CODE&gt; and &lt;CODE&gt;^17&lt;/CODE&gt; in your existing eval so that it finds the pattern only in the beginning of the string i.e. : &lt;CODE&gt;| eval FDate2=case(match(FDate1,"^17","20".FDate1,FDate1)&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Other option would be perform eval based on length of extracted date field and to prefix 20 to date if length of date field in file is 6 and not 8 (following is run anywhere search to test the same):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval oldsourcefile="blahblah._D20170118"
| rex field=oldsourcefile ".D(?&amp;lt;FDate1&amp;gt;\d{6,8})"
| eval FDate2=if(len(FDate1)==6,"20".FDate1,FDate1)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 14 Jul 2017 12:02:48 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2017-07-14T12:02:48Z</dc:date>
    <item>
      <title>Eval Match function Issue</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-Match-function-Issue/m-p/306927#M92065</link>
      <description>&lt;P&gt;I need to extract the date from the file name,But  the format of the data on  different files are different for eg:D20171202 is one file format,other one is D171203. I am extracting the date using regex and using eval match function I am changing the date format it is working fine , but it is changing some files date only. &lt;/P&gt;

&lt;P&gt;below is the code I used &lt;BR /&gt;
index=xyz  source=a&lt;BR /&gt;
| rex field=oldsorcefile".&lt;EM&gt;_D(?\d{8}).&lt;/EM&gt;"&lt;BR /&gt;
|eval FDate2=case(macth(FDate1,"20*")FDate1,match(FDate,"17*"),("20"+(FDate1)))&lt;BR /&gt;
| table Fdate1,FDate2&lt;/P&gt;

&lt;P&gt;Here is the  Sample output...&lt;/P&gt;

&lt;P&gt;FDATE1                 FDATE2&lt;BR /&gt;
17071318             2017071318&lt;BR /&gt;
17071418            2017071418&lt;BR /&gt;
20170714            20170714&lt;BR /&gt;
20170712            20170712&lt;BR /&gt;
17071216            17071216&lt;/P&gt;

&lt;P&gt;it is working fine but  some dates are not changing according to code. any help would be great full.&lt;BR /&gt;
Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 14:52:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-Match-function-Issue/m-p/306927#M92065</guid>
      <dc:creator>vikasreddy</dc:creator>
      <dc:date>2020-09-29T14:52:24Z</dc:date>
    </item>
    <item>
      <title>Re: Eval Match function Issue</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-Match-function-Issue/m-p/306928#M92066</link>
      <description>&lt;P&gt;Based on your description Date can be 6 digits (YYMMDD) or 8 digits (YYYYMMDD). Which is followed by &lt;CODE&gt;._D&lt;/CODE&gt; in the filename.&lt;BR /&gt;
I expect your existing logic to fail when you have two 20s or two 17s in the date like &lt;STRONG&gt;20170220&lt;/STRONG&gt; or &lt;STRONG&gt;170117&lt;/STRONG&gt; etc. &lt;/P&gt;

&lt;P&gt;One of the ways would be to match &lt;CODE&gt;^20&lt;/CODE&gt; and &lt;CODE&gt;^17&lt;/CODE&gt; in your existing eval so that it finds the pattern only in the beginning of the string i.e. : &lt;CODE&gt;| eval FDate2=case(match(FDate1,"^17","20".FDate1,FDate1)&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Other option would be perform eval based on length of extracted date field and to prefix 20 to date if length of date field in file is 6 and not 8 (following is run anywhere search to test the same):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval oldsourcefile="blahblah._D20170118"
| rex field=oldsourcefile ".D(?&amp;lt;FDate1&amp;gt;\d{6,8})"
| eval FDate2=if(len(FDate1)==6,"20".FDate1,FDate1)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Jul 2017 12:02:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-Match-function-Issue/m-p/306928#M92066</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-07-14T12:02:48Z</dc:date>
    </item>
    <item>
      <title>Re: Eval Match function Issue</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-Match-function-Issue/m-p/306929#M92067</link>
      <description>&lt;P&gt;try this -&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw = "D171228  other stuff D20170521  more stuff D180521" 
| rename COMMENT as "The above just makes test data for correcting the _raw"

| rename COMMENT as "This changes all 6-digit dates in the _raw starting with D17 through D19 to D2017 through D2019"
| rename COMMENT as "so the solution will not break for over two years"
| rex field=_raw mode=sed "s/\bD(1[7|8|9]\d{4})\b/D20\1/g"


| makeresults 
| eval mydate = "D171228 D20170521 D180521" 
| makemv mydate 
| mvexpand mydate
| rename COMMENT as "The above just makes test data for changing a specific already-extracted date field."

| rename COMMENT as "This changes all 6-digit dates in that field starting with D17 through D19 to D2017 through D2019"
| rename COMMENT as "so the solution will not break for over two years"
| rename COMMENT as "this will work on a multivalue field as well, to demo just remove the mvexpand command"
| rex field=mydate mode=sed "s/^D(1[7|8|9]\d{4})$/D20\1/g"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Jul 2017 15:09:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-Match-function-Issue/m-p/306929#M92067</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-07-14T15:09:59Z</dc:date>
    </item>
    <item>
      <title>Re: Eval Match function Issue</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-Match-function-Issue/m-p/306930#M92068</link>
      <description>&lt;P&gt;Ya, it worked Thank you Niketnilay.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2017 15:51:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-Match-function-Issue/m-p/306930#M92068</guid>
      <dc:creator>vikasreddy</dc:creator>
      <dc:date>2017-07-14T15:51:12Z</dc:date>
    </item>
    <item>
      <title>Re: Eval Match function Issue</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-Match-function-Issue/m-p/306931#M92069</link>
      <description>&lt;P&gt;@vikasreddy, have you tried the option suggested by DalJeanis, it employs single rex command with sed to format field as per you need. I think that is a better option.&lt;/P&gt;</description>
      <pubDate>Sat, 15 Jul 2017 08:53:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-Match-function-Issue/m-p/306931#M92069</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-07-15T08:53:55Z</dc:date>
    </item>
    <item>
      <title>Re: Eval Match function Issue</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-Match-function-Issue/m-p/306932#M92070</link>
      <description>&lt;P&gt;Thank you DalJeanis, For you quick reply. It was awesome  the whole thing can be done with single line.&lt;/P&gt;</description>
      <pubDate>Sat, 15 Jul 2017 09:08:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-Match-function-Issue/m-p/306932#M92070</guid>
      <dc:creator>vikasreddy</dc:creator>
      <dc:date>2017-07-15T09:08:22Z</dc:date>
    </item>
    <item>
      <title>Re: Eval Match function Issue</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-Match-function-Issue/m-p/306933#M92071</link>
      <description>&lt;P&gt;@Niketnilay,Ya it is working for me, I have tried your options it is working later, I have made some tweaks in my code suggested by DalJeanis.&lt;/P&gt;</description>
      <pubDate>Sat, 15 Jul 2017 09:11:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-Match-function-Issue/m-p/306933#M92071</guid>
      <dc:creator>vikasreddy</dc:creator>
      <dc:date>2017-07-15T09:11:36Z</dc:date>
    </item>
    <item>
      <title>Re: Eval Match function Issue</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-Match-function-Issue/m-p/306934#M92072</link>
      <description>&lt;P&gt;@vikasreddy, if DalJeanis' answer also helped, please upvote his comment. I have already done the same.&lt;/P&gt;</description>
      <pubDate>Sun, 16 Jul 2017 03:20:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-Match-function-Issue/m-p/306934#M92072</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-07-16T03:20:02Z</dc:date>
    </item>
  </channel>
</rss>

