<?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: extracting the first 3 characters from a field? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/extracting-the-first-3-characters-from-a-field/m-p/666634#M228678</link>
    <description>&lt;P&gt;Tested the rex and substr, which works perfect. The abstract giving some troubles, will check it again.&amp;nbsp;&lt;BR /&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/9.1.1/SearchReference/Abstract" target="_blank"&gt;https://docs.splunk.com/Documentation/Splunk/9.1.1/SearchReference/Abstract&lt;/A&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;|makeresults 
| eval samplelog="h1 #_\"he$$llohibye"
| rex field=samplelog "^(?P&amp;lt;EightCharsRex&amp;gt;........)" 
| eval EightCharsSubStr=substr(samplelog,1,8)
```| abstract maxterms=9 maxlines=1```
| table samplelog EightCharsRex EightCharsSubStr&lt;/LI-CODE&gt;&lt;P&gt;this produces this result:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;samplelog	        EightCharsRex	EightCharsSubStr
h1 #_"he$$llohibye	h1 #_"he	h1 #_"he&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 30 Oct 2023 01:38:43 GMT</pubDate>
    <dc:creator>inventsekar</dc:creator>
    <dc:date>2023-10-30T01:38:43Z</dc:date>
    <item>
      <title>extracting the first 3 characters from a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extracting-the-first-3-characters-from-a-field/m-p/190318#M54785</link>
      <description>&lt;P&gt;How do I extract the first 3 characters from a field ?&lt;/P&gt;

&lt;P&gt;I thought it might be something like &lt;CODE&gt;... | eval First3=substring(fieldname,3)&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Anyone know the function or regex that would do this?&lt;/P&gt;</description>
      <pubDate>Fri, 20 Mar 2015 02:52:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extracting-the-first-3-characters-from-a-field/m-p/190318#M54785</guid>
      <dc:creator>HattrickNZ</dc:creator>
      <dc:date>2015-03-20T02:52:47Z</dc:date>
    </item>
    <item>
      <title>Re: extracting the first 3 characters from a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extracting-the-first-3-characters-from-a-field/m-p/190319#M54786</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;rex field=fieldname "^(?P&amp;lt;first3&amp;gt;...)”
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Mar 2015 02:58:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extracting-the-first-3-characters-from-a-field/m-p/190319#M54786</guid>
      <dc:creator>cpetterborg</dc:creator>
      <dc:date>2015-03-20T02:58:44Z</dc:date>
    </item>
    <item>
      <title>Re: extracting the first 3 characters from a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extracting-the-first-3-characters-from-a-field/m-p/190320#M54787</link>
      <description>&lt;P&gt;Hi Hattrick,&lt;/P&gt;

&lt;P&gt;To achieve this, you can use either "rex" or "substr" function. For example:&lt;/P&gt;

&lt;P&gt;You have a field called "&lt;STRONG&gt;name&lt;/STRONG&gt;" and the value is "&lt;STRONG&gt;Mario&lt;/STRONG&gt;"&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Using rex:&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex field=name "(?P&amp;lt;subname&amp;gt;\w{3}).*"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Using substr:&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval subname=substr(name,1,3)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Both should produce "Mar"&lt;/P&gt;

&lt;P&gt;Reference: &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.2/SearchReference/CommonEvalFunctions"&gt;http://docs.splunk.com/Documentation/Splunk/6.2.2/SearchReference/CommonEvalFunctions&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Mar 2015 05:40:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extracting-the-first-3-characters-from-a-field/m-p/190320#M54787</guid>
      <dc:creator>vincenteous</dc:creator>
      <dc:date>2015-03-20T05:40:15Z</dc:date>
    </item>
    <item>
      <title>Re: extracting the first 3 characters from a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extracting-the-first-3-characters-from-a-field/m-p/190321#M54788</link>
      <description>&lt;P&gt;hi HattrickNZ&lt;/P&gt;

&lt;P&gt;If you already have the field that you want to extract their 3 first characters try to use this  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    ....... | eval First3=substr(fieldname,1,3) 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;For example with access_combined sourcetype you can extract the 3 first characters of clientip field and use it to count the number of events by cli3 like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; sourcetype=access_* | eval cli3=substr(clientip , 1 ,3) |stats count by cli3
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Mar 2015 08:08:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extracting-the-first-3-characters-from-a-field/m-p/190321#M54788</guid>
      <dc:creator>chimell</dc:creator>
      <dc:date>2015-03-20T08:08:11Z</dc:date>
    </item>
    <item>
      <title>Re: extracting the first 3 characters from a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extracting-the-first-3-characters-from-a-field/m-p/190322#M54789</link>
      <description>&lt;P&gt;Your &lt;CODE&gt;rex&lt;/CODE&gt; will only catch the first three &lt;EM&gt;word characters&lt;/EM&gt;. If there is punctuation, it will move on until it finds word characters, which may not be the first three characters. If the field contains "&lt;STRONG&gt;a-bc-def&lt;/STRONG&gt;" then your &lt;CODE&gt;rex&lt;/CODE&gt; would match "&lt;STRONG&gt;def&lt;/STRONG&gt;" not "&lt;STRONG&gt;a-b&lt;/STRONG&gt;".&lt;/P&gt;</description>
      <pubDate>Fri, 20 Mar 2015 15:54:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extracting-the-first-3-characters-from-a-field/m-p/190322#M54789</guid>
      <dc:creator>cpetterborg</dc:creator>
      <dc:date>2015-03-20T15:54:46Z</dc:date>
    </item>
    <item>
      <title>Re: extracting the first 3 characters from a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extracting-the-first-3-characters-from-a-field/m-p/190323#M54790</link>
      <description>&lt;P&gt;Right, missed that one. Thank for the notice&lt;/P&gt;</description>
      <pubDate>Fri, 20 Mar 2015 16:29:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extracting-the-first-3-characters-from-a-field/m-p/190323#M54790</guid>
      <dc:creator>vincenteous</dc:creator>
      <dc:date>2015-03-20T16:29:23Z</dc:date>
    </item>
    <item>
      <title>Re: extracting the first 3 characters from a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extracting-the-first-3-characters-from-a-field/m-p/190324#M54791</link>
      <description>&lt;P&gt;tks, perfect&lt;/P&gt;</description>
      <pubDate>Mon, 23 Mar 2015 02:29:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extracting-the-first-3-characters-from-a-field/m-p/190324#M54791</guid>
      <dc:creator>HattrickNZ</dc:creator>
      <dc:date>2015-03-23T02:29:04Z</dc:date>
    </item>
    <item>
      <title>Re: extracting the first 3 characters from a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extracting-the-first-3-characters-from-a-field/m-p/190325#M54792</link>
      <description>&lt;P&gt;Interesting note , I used 3 methods to get characters and deal with several lines in my data:&lt;/P&gt;

&lt;P&gt;| abstract maxterms=24 maxlines=1&lt;BR /&gt;
-I wanted to only see the first line but this pulled 24 characters into one line.  Not too bad though.&lt;/P&gt;

&lt;P&gt;| rex "^(?.{24})"&lt;BR /&gt;
-Did not match the new line, returned nothing if first line was shorter than 24 characters.&lt;/P&gt;

&lt;P&gt;| eval TIME=substr(_raw,1,24)&lt;BR /&gt;
-Going to use this one.&lt;/P&gt;

&lt;P&gt;Using this to look at TIME_PREFIX, MAX_TIMESTAMP_LOOKAHEAD, and TIME_FORMAT settings in bulk.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 17:16:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extracting-the-first-3-characters-from-a-field/m-p/190325#M54792</guid>
      <dc:creator>gbower333</dc:creator>
      <dc:date>2020-09-29T17:16:36Z</dc:date>
    </item>
    <item>
      <title>Re: extracting the first 3 characters from a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extracting-the-first-3-characters-from-a-field/m-p/666616#M228675</link>
      <description>&lt;P&gt;I am not sure if this option was available in 2015 but as of today the easier way to do this would be with&amp;nbsp;the use of one of the text functions with the EVAL command.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;Usage: substr(&amp;lt;str&amp;gt;,&amp;lt;start&amp;gt;,&amp;lt;length&amp;gt;)&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;In your case:&lt;BR /&gt;&lt;STRONG&gt;&lt;EM&gt;| eval n=substr("your_string", 1, 3)&amp;nbsp;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 29 Oct 2023 12:16:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extracting-the-first-3-characters-from-a-field/m-p/666616#M228675</guid>
      <dc:creator>shahrukhvp</dc:creator>
      <dc:date>2023-10-29T12:16:10Z</dc:date>
    </item>
    <item>
      <title>Re: extracting the first 3 characters from a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extracting-the-first-3-characters-from-a-field/m-p/666634#M228678</link>
      <description>&lt;P&gt;Tested the rex and substr, which works perfect. The abstract giving some troubles, will check it again.&amp;nbsp;&lt;BR /&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/9.1.1/SearchReference/Abstract" target="_blank"&gt;https://docs.splunk.com/Documentation/Splunk/9.1.1/SearchReference/Abstract&lt;/A&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;|makeresults 
| eval samplelog="h1 #_\"he$$llohibye"
| rex field=samplelog "^(?P&amp;lt;EightCharsRex&amp;gt;........)" 
| eval EightCharsSubStr=substr(samplelog,1,8)
```| abstract maxterms=9 maxlines=1```
| table samplelog EightCharsRex EightCharsSubStr&lt;/LI-CODE&gt;&lt;P&gt;this produces this result:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;samplelog	        EightCharsRex	EightCharsSubStr
h1 #_"he$$llohibye	h1 #_"he	h1 #_"he&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2023 01:38:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extracting-the-first-3-characters-from-a-field/m-p/666634#M228678</guid>
      <dc:creator>inventsekar</dc:creator>
      <dc:date>2023-10-30T01:38:43Z</dc:date>
    </item>
  </channel>
</rss>

