<?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 how can i trim until a specific character? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/how-can-i-trim-until-a-specific-character/m-p/325797#M162663</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I got a field that has a format and a value like this "S01-3101" and sometimes a value like this "S01-301" &lt;BR /&gt;
i just want to get the value of 01 near the letter S and i want to trim the S and "-3101" . &lt;/P&gt;

&lt;P&gt;My idea is to trim the value after the "-" and itself, but i dont know if it is possible.&lt;/P&gt;

&lt;P&gt;Thank you for your answers!!!!!&lt;/P&gt;</description>
    <pubDate>Thu, 01 Mar 2018 07:59:50 GMT</pubDate>
    <dc:creator>ygdrassil</dc:creator>
    <dc:date>2018-03-01T07:59:50Z</dc:date>
    <item>
      <title>how can i trim until a specific character?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-can-i-trim-until-a-specific-character/m-p/325797#M162663</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I got a field that has a format and a value like this "S01-3101" and sometimes a value like this "S01-301" &lt;BR /&gt;
i just want to get the value of 01 near the letter S and i want to trim the S and "-3101" . &lt;/P&gt;

&lt;P&gt;My idea is to trim the value after the "-" and itself, but i dont know if it is possible.&lt;/P&gt;

&lt;P&gt;Thank you for your answers!!!!!&lt;/P&gt;</description>
      <pubDate>Thu, 01 Mar 2018 07:59:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-can-i-trim-until-a-specific-character/m-p/325797#M162663</guid>
      <dc:creator>ygdrassil</dc:creator>
      <dc:date>2018-03-01T07:59:50Z</dc:date>
    </item>
    <item>
      <title>Re: how can i trim until a specific character?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-can-i-trim-until-a-specific-character/m-p/325798#M162664</link>
      <description>&lt;P&gt;try this regex:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;   ... |rex field=&amp;lt;fieldname&amp;gt;"^.(?&amp;lt;test&amp;gt;\d+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Try this run anywhere search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|makeresults|eval _raw="S01-3101"|rex field=_raw"^.(?&amp;lt;test&amp;gt;\d+)"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Mar 2018 12:44:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-can-i-trim-until-a-specific-character/m-p/325798#M162664</guid>
      <dc:creator>493669</dc:creator>
      <dc:date>2018-03-01T12:44:11Z</dc:date>
    </item>
    <item>
      <title>Re: how can i trim until a specific character?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-can-i-trim-until-a-specific-character/m-p/325799#M162665</link>
      <description>&lt;P&gt;Thank you for the answers , i already answer this question by using substrt()&lt;/P&gt;</description>
      <pubDate>Mon, 05 Mar 2018 03:12:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-can-i-trim-until-a-specific-character/m-p/325799#M162665</guid>
      <dc:creator>ygdrassil</dc:creator>
      <dc:date>2018-03-05T03:12:54Z</dc:date>
    </item>
    <item>
      <title>Re: how can i trim until a specific character?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-can-i-trim-until-a-specific-character/m-p/325800#M162666</link>
      <description>&lt;P&gt;@ygdrassil, please go ahead and mention your approach to fix the issue and Accept the same as answer.&lt;/P&gt;

&lt;P&gt;In your question you have first mentioned that you are interested in digits after S and then also digits after &lt;CODE&gt;dot (.)&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;YourBaseSearch&amp;gt; yourFieldName=*
| rex field=yourFieldName "S(?&amp;lt;firstField&amp;gt;[^-]+)-(?&amp;lt;secondField&amp;gt;\d+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If the field value is present on the events you are interested in and you always need this extraction you should check out Field Extraction Knowledge Objects (this way the regular expression based field extraction will persist as Knowledge Object and can be easily maintained and reused.).&lt;/P&gt;

&lt;P&gt;Following are some of Splunk Documentation reference for the same: &lt;A href="http://docs.splunk.com/Documentation/SplunkCloud/latest/Search/Extractfieldswithsearchcommands"&gt;http://docs.splunk.com/Documentation/SplunkCloud/latest/Search/Extractfieldswithsearchcommands&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/Knowledge/Aboutfields"&gt;http://docs.splunk.com/Documentation/Splunk/latest/Knowledge/Aboutfields&lt;/A&gt;&lt;BR /&gt;
Following is a run anywhere search based on sample data provided:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval yourFieldName="S01-3101,S01-301"
| makemv yourFieldName delim="," 
| mvexpand yourFieldName
| rex field=yourFieldName "S(?&amp;lt;firstField&amp;gt;[^-]+)-(?&amp;lt;secondField&amp;gt;\d+)"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 05 Mar 2018 07:30:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-can-i-trim-until-a-specific-character/m-p/325800#M162666</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-03-05T07:30:27Z</dc:date>
    </item>
  </channel>
</rss>

