<?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 Extract a string in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Extract-a-string/m-p/82145#M181890</link>
    <description>&lt;P&gt;Hi we log the data in splunk as below &lt;/P&gt;

&lt;P&gt;2013-01-07 09:37:35.556935 client="rmf-rm3d"|jobRunId="1504312"|salesforceId="null"|JobDurationSecs="183.561"|description="null"|processid="bzghn-3i8-4hg7"|schedulerId="id.20130107_093409.rmf-rm3d.rm3d.1375765"|numberOfCompletedSteps="9"|positionsProxied="27"|client="rmf-rm3d"|reportsCount="0"|portfoliosSplit="1"|parts="Import"|reportsSize="0"|positionsAttempted="520"|jobName="rm3d"|autoSysID="1375765"|............&lt;/P&gt;

&lt;P&gt;we have a field called controlFiles="m_ifs_swr_d_1.20130103.cntl.txt"&lt;/P&gt;

&lt;P&gt;I have the query to extract the control file as its a variable but what I want is just the 1st part &lt;BR /&gt;
m_ifs_swr_d_1  and not 20130103.cntl.txt.&lt;/P&gt;

&lt;P&gt;now the 1st and the 2nd part are not of fixed length but can be maximum 3 &lt;BR /&gt;
what I mean is the format for the control file is &lt;/P&gt;

&lt;P&gt;&lt;FILENAMEPART1&gt;.&lt;FILENAMEPART2&gt;.&lt;DATE&gt;.&lt;CNTL&gt;.&lt;FILETYPE&gt;&lt;/FILETYPE&gt;&lt;/CNTL&gt;&lt;/DATE&gt;&lt;/FILENAMEPART2&gt;&lt;/FILENAMEPART1&gt;&lt;/P&gt;

&lt;P&gt;now filename can be part1 or part2 or part3 usually its two parts. but the only constant in the format is &lt;DATE&gt;.cntl even the file type may or may not be present (usually its not) so I want to extract anything thats before the &lt;DATE&gt;.cntl &lt;/DATE&gt;&lt;/DATE&gt;&lt;/P&gt;

&lt;P&gt;how can I achieve this. &lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 13:04:13 GMT</pubDate>
    <dc:creator>ashu_g50</dc:creator>
    <dc:date>2020-09-28T13:04:13Z</dc:date>
    <item>
      <title>Extract a string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-a-string/m-p/82145#M181890</link>
      <description>&lt;P&gt;Hi we log the data in splunk as below &lt;/P&gt;

&lt;P&gt;2013-01-07 09:37:35.556935 client="rmf-rm3d"|jobRunId="1504312"|salesforceId="null"|JobDurationSecs="183.561"|description="null"|processid="bzghn-3i8-4hg7"|schedulerId="id.20130107_093409.rmf-rm3d.rm3d.1375765"|numberOfCompletedSteps="9"|positionsProxied="27"|client="rmf-rm3d"|reportsCount="0"|portfoliosSplit="1"|parts="Import"|reportsSize="0"|positionsAttempted="520"|jobName="rm3d"|autoSysID="1375765"|............&lt;/P&gt;

&lt;P&gt;we have a field called controlFiles="m_ifs_swr_d_1.20130103.cntl.txt"&lt;/P&gt;

&lt;P&gt;I have the query to extract the control file as its a variable but what I want is just the 1st part &lt;BR /&gt;
m_ifs_swr_d_1  and not 20130103.cntl.txt.&lt;/P&gt;

&lt;P&gt;now the 1st and the 2nd part are not of fixed length but can be maximum 3 &lt;BR /&gt;
what I mean is the format for the control file is &lt;/P&gt;

&lt;P&gt;&lt;FILENAMEPART1&gt;.&lt;FILENAMEPART2&gt;.&lt;DATE&gt;.&lt;CNTL&gt;.&lt;FILETYPE&gt;&lt;/FILETYPE&gt;&lt;/CNTL&gt;&lt;/DATE&gt;&lt;/FILENAMEPART2&gt;&lt;/FILENAMEPART1&gt;&lt;/P&gt;

&lt;P&gt;now filename can be part1 or part2 or part3 usually its two parts. but the only constant in the format is &lt;DATE&gt;.cntl even the file type may or may not be present (usually its not) so I want to extract anything thats before the &lt;DATE&gt;.cntl &lt;/DATE&gt;&lt;/DATE&gt;&lt;/P&gt;

&lt;P&gt;how can I achieve this. &lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 13:04:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-a-string/m-p/82145#M181890</guid>
      <dc:creator>ashu_g50</dc:creator>
      <dc:date>2020-09-28T13:04:13Z</dc:date>
    </item>
    <item>
      <title>Re: Extract a string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-a-string/m-p/82146#M181891</link>
      <description>&lt;P&gt;If you only want the text up to, but not including the first dot (.) - which seems to be the pattern here - you can do it inline through a &lt;CODE&gt;rex&lt;/CODE&gt; statement.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your search | rex field = controlFiles "(?&amp;lt;ctrlfile&amp;gt;[^.]+)\." | the rest of your search
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That gives you a new field called &lt;CODE&gt;ctrlfile&lt;/CODE&gt; that only contains the first part.&lt;/P&gt;

&lt;P&gt;If you want the field to contain everything (including dots) but date.cntl.txt, you could try:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your search | rex field = controlFiles "(?&amp;lt;ctrlfile&amp;gt;.*)\.\d{10}\.cntl\.txt" | the rest of your search
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You probably understand how to take if from here if these patterns are not correct. If not, ask for a clarification.&lt;/P&gt;

&lt;P&gt;Hope this helps,&lt;/P&gt;

&lt;P&gt;Kristian&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jan 2013 13:28:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-a-string/m-p/82146#M181891</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2013-01-09T13:28:19Z</dc:date>
    </item>
    <item>
      <title>Re: Extract a string</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-a-string/m-p/82147#M181892</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;

&lt;P&gt;Here you have another option:&lt;BR /&gt;
Regular Expression:&lt;BR /&gt;
controlFiles="(?&lt;PART1&gt;\w*).(?&lt;PART2&gt;\w+)?.?(?&lt;PART3&gt;\w+)?.?\d+.cntl.\w+"&lt;/PART3&gt;&lt;/PART2&gt;&lt;/PART1&gt;&lt;/P&gt;

&lt;P&gt;Splunk Command:&lt;/P&gt;

&lt;P&gt;... | rex field = controlFiles "controlFiles="(?&lt;PART1&gt;\w*).(?&lt;PART2&gt;\w+)?.?(?&lt;PART3&gt;\w+)?.?\d+.cntl.\w+"" | ...&lt;/PART3&gt;&lt;/PART2&gt;&lt;/PART1&gt;&lt;/P&gt;

&lt;P&gt;I tried it with RegExRX and it works for me&lt;/P&gt;

&lt;P&gt;Try it and let me know if it doesn´t work for you&lt;/P&gt;

&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jan 2013 15:38:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-a-string/m-p/82147#M181892</guid>
      <dc:creator>gfuente</dc:creator>
      <dc:date>2013-01-09T15:38:36Z</dc:date>
    </item>
  </channel>
</rss>

