<?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 add my regular expression to a search? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-add-my-regular-expression-to-a-search/m-p/274422#M82780</link>
    <description>&lt;P&gt;Hey, Rich, do you think the group parens around &lt;CODE&gt;"^(.*)bytes"&lt;/CODE&gt; are causing any issues?  Seems like it ought to be either &lt;CODE&gt;"^(?:.*)bytes"&lt;/CODE&gt; or &lt;CODE&gt;"^.*bytes"&lt;/CODE&gt;.&lt;/P&gt;</description>
    <pubDate>Fri, 03 Feb 2017 21:05:43 GMT</pubDate>
    <dc:creator>DalJeanis</dc:creator>
    <dc:date>2017-02-03T21:05:43Z</dc:date>
    <item>
      <title>How to add my regular expression to a search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-add-my-regular-expression-to-a-search/m-p/274417#M82775</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;

&lt;P&gt;I have a regular expression  &lt;CODE&gt;^(.*)bytes read (?P\d+) written (?P\d+)$&lt;/CODE&gt;, where i edited the proper regular expression from a field to this to get output of particular users info to read the values of read and write. I have a search which will display the user session_id, file_name, time, ip. So, i just wanna add the regular expression to my search so that READ and WRITE values of a particular field of a user will be popping up.&lt;/P&gt;

&lt;P&gt;My search is&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=sftp USER=gradydftsftpdata SESSION_ID=* | table USER, SESSION_ID,USER_IP,date_hour,_time | dedup SESSION_ID,USER_IP| join type=left max=2 SESSION_ID [search index=sftp SESSION_ID=* date_hour=* ACTION="open" OR ACTION="close" | table SESSION_ID, FILE_NAME, _time, USER_IP, ACTION] | table FILE_NAME,USER, SESSION_ID,USER_IP,date_hour,_time,ACTION | dedup FILE_NAME,ACTION
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and my regular expression is    &lt;CODE&gt;^(.*)bytes read (?P\d+) written (?P\d+)$&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;Do we need to use join or transaction in this search??&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 12:42:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-add-my-regular-expression-to-a-search/m-p/274417#M82775</guid>
      <dc:creator>sujith0311</dc:creator>
      <dc:date>2020-09-29T12:42:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to add my regular expression to a search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-add-my-regular-expression-to-a-search/m-p/274418#M82776</link>
      <description>&lt;P&gt;Nope.  Basically, you need to look at your search and figure out where those words will exist in the underlying data, then use your regular expression to extract them into a named capture group.  &lt;/P&gt;

&lt;P&gt;Assuming that those words are appearing on the "open" and "close" events in the inside search, your code would look something like this - &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index=sftp USER=gradydftsftpdata SESSION_ID=* 
| table SESSION_ID, USER_IP,  USER, date_hour, _time 
| dedup SESSION_ID, USER_IP
| join type=left max=2 SESSION_ID 
    [search index=sftp SESSION_ID=* ACTION="open" OR ACTION="close" 
    | rex field=_raw "^(.*)bytes read (?P&amp;lt;BytesRead&amp;gt;\d+) written (?P&amp;lt;BytesWritten&amp;gt;\d+)$"
    | table SESSION_ID, FILE_NAME, ACTION, BytesRead, BytesWritten, _time 
    ] 
| table SESSION_ID, USER_IP, USER, FILE_NAME, ACTION,  BytesRead, BytesWritten, date_hour, _time
| sort FILE_NAME, ACTION, -_time
| dedup FILE_NAME, ACTION
| table FILE_NAME, USER, ACTION, date_hour, _time, SESSION_ID, USER_IP 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;Notes - &lt;/P&gt;

&lt;P&gt;I've reordered the fields based on the logic involved, and then at the end presented them in the order you were outputing them.  I find it's helpful to think hierarchically while building the extract.  The fields to the farthest left are the "driver" fields, and the ones to the far right are "along for the ride".&lt;/P&gt;

&lt;P&gt;You are not using  USER_IP in the join, and it's already on the left records going into the join, so it doesn't need to be returned in the output table from the join.  I've removed it from the output table, but if there is a reason - such as the session IDs not being unique without it - then you can put it back and add it as a join field after SESSION_ID outside the first bracket.&lt;/P&gt;

&lt;P&gt;For your join code to be right, a session must only be uploading or downloading one file.  I suspect that there may be an issue with the extract of the byte data, so start with this chunk , over a recent period of time, to test the extract -&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    search index=sftp SESSION_ID=* ACTION="open" OR ACTION="close" | head 5
    | rex field=_raw "^(.*)bytes read (?P&amp;lt;BytesRead&amp;gt;\d+) written (?P&amp;lt;BytesWritten&amp;gt;\d+)$"
    | table SESSION_ID, USER_IP, FILE_NAME, ACTION, BytesRead, BytesWritten, _time 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Your final dedup assumes that only one person and/or session will be uploading and/or downloading your file over any given time period.  That doesn't seem right, but I've added a sort to retain the most RECENT upload or download, just in case it is correct for your purposes. &lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;corrected typo&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 12:42:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-add-my-regular-expression-to-a-search/m-p/274418#M82776</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2020-09-29T12:42:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to add my regular expression to a search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-add-my-regular-expression-to-a-search/m-p/274419#M82777</link>
      <description>&lt;P&gt;I found this error Error in 'rex' command: The regex 'fields=_raw' does not extract anything. It should specify at least one named group. Format: (?...).. what does it exactly mean&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2017 20:52:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-add-my-regular-expression-to-a-search/m-p/274419#M82777</guid>
      <dc:creator>sujith0311</dc:creator>
      <dc:date>2017-02-02T20:52:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to add my regular expression to a search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-add-my-regular-expression-to-a-search/m-p/274420#M82778</link>
      <description>&lt;P&gt;The correct syntax is &lt;CODE&gt;field=_raw&lt;/CODE&gt; (the keyword is singular).  The default is to search _raw so the field keyword is not needed in this instance.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Feb 2017 20:28:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-add-my-regular-expression-to-a-search/m-p/274420#M82778</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2017-02-03T20:28:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to add my regular expression to a search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-add-my-regular-expression-to-a-search/m-p/274421#M82779</link>
      <description>&lt;P&gt;Certainly wasn't rields=_raw, the way i had it.  Must have been Scooby-Doo that did my editing. &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;In my demo code, I tend to be explicit with the defaults, since questioners are usually pretty confused by rex and regex, so showing them explicitly WHAT the rex command is comparing the regex against seems to be a good idea.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Feb 2017 21:03:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-add-my-regular-expression-to-a-search/m-p/274421#M82779</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-02-03T21:03:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to add my regular expression to a search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-add-my-regular-expression-to-a-search/m-p/274422#M82780</link>
      <description>&lt;P&gt;Hey, Rich, do you think the group parens around &lt;CODE&gt;"^(.*)bytes"&lt;/CODE&gt; are causing any issues?  Seems like it ought to be either &lt;CODE&gt;"^(?:.*)bytes"&lt;/CODE&gt; or &lt;CODE&gt;"^.*bytes"&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Feb 2017 21:05:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-add-my-regular-expression-to-a-search/m-p/274422#M82780</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-02-03T21:05:43Z</dc:date>
    </item>
  </channel>
</rss>

