<?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 count number of unique part of string from log? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-number-of-unique-part-of-string-from-log/m-p/579257#M201864</link>
    <description>&lt;P&gt;Kindly accept the answer, so it will be useful for other visitors.&lt;/P&gt;</description>
    <pubDate>Sun, 26 Dec 2021 07:14:18 GMT</pubDate>
    <dc:creator>VatsalJagani</dc:creator>
    <dc:date>2021-12-26T07:14:18Z</dc:date>
    <item>
      <title>How to count number of unique part of string from log?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-number-of-unique-part-of-string-from-log/m-p/578846#M201731</link>
      <description>&lt;P&gt;In my logfile I need to count a unique piece of string. This string is many times in the logfile.&lt;BR /&gt;The unique parts (bold within this example string, the capital &lt;STRONG&gt;NNNN&lt;/STRONG&gt;&amp;nbsp;is a number but not known how many digits and the capital &lt;STRONG&gt;CCC&lt;/STRONG&gt; are optional filled with a number or character but also not known how many characters) it is always separated by underscores:&lt;BR /&gt;"ID": "20201218_HD_111111_20201218_HD_111111_1111_&lt;STRONG&gt;1000AB_NNNN_CCC&lt;/STRONG&gt;_BE"&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Your help is much appreciated with this query.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Dec 2021 16:13:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-number-of-unique-part-of-string-from-log/m-p/578846#M201731</guid>
      <dc:creator>jkauling</dc:creator>
      <dc:date>2021-12-19T16:13:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to count number of unique part of string from log?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-number-of-unique-part-of-string-from-log/m-p/578847#M201732</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/241605"&gt;@jkauling&lt;/a&gt;&amp;nbsp;- You can use the `rex` command.&lt;/P&gt;&lt;P&gt;You can add the below commands at the end of your query to see how many events contain given formatted events.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex "_1000AB_(?&amp;lt;extracted_number&amp;gt;\d+)_\w+_"
| search extracted_number=*
| stats count&lt;/LI-CODE&gt;&lt;P&gt;- If you remove `| stats count` to see the extracted_number field as well.&lt;/P&gt;&lt;P&gt;- If the `ID` field is already being extracted you can replace regex with the below line to improve regex performance.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex field=ID "_1000AB_(?&amp;lt;extracted_number&amp;gt;\d+)_\w+_"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- If you also expect to see multiple places having this string (single event containing multiple of this unique string) and you like to count them separately, change the rex line with the below line:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex "_1000AB_(?&amp;lt;extracted_number&amp;gt;\d+)_\w+_" max_match=0 | mvexpand extracted_number&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Dec 2021 16:34:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-number-of-unique-part-of-string-from-log/m-p/578847#M201732</guid>
      <dc:creator>VatsalJagani</dc:creator>
      <dc:date>2021-12-19T16:34:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to count number of unique part of string from log?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-number-of-unique-part-of-string-from-log/m-p/578855#M201737</link>
      <description>&lt;P&gt;With&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;grep, filter out just the numbers:&lt;/P&gt;&lt;PRE&gt;grep -Eo &lt;SPAN class=""&gt;'[0-9]+-'&lt;/SPAN&gt; file | sort -u | wc -l&lt;/PRE&gt;&lt;UL&gt;&lt;LI&gt;[0-9]&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;Matches any character between 0 and 9 (any digit).&lt;/LI&gt;&lt;LI&gt;+&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;in&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://www.gnu.org/software/grep/manual/html_node/Fundamental-Structure.html#Fundamental-Structure" target="_blank" rel="nofollow noopener"&gt;extended regular expressions&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;stands for at least one character (that's why the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;-E&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;option is used with&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;grep). So&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;[0-9]+-&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;matches one or more digits, followed by&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;-.&lt;/LI&gt;&lt;LI&gt;-o&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;only prints the part that matched your pattern, so given input&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;abcd23-gf56,&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;grep&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;will only print&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;23-.&lt;/LI&gt;&lt;LI&gt;sort -u&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;sorts and filters unique entries (due to&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;-u), and&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;wc -l&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;counts the number of lines in input (hence, the number of unique entries&lt;SPAN&gt;headset compatible with &lt;FONT color="#003300"&gt;&lt;A href="https://screamreality.com/best-vr-headset-for-mac/" target="_self"&gt;macbook pro&lt;/A&gt;&lt;/FONT&gt;&lt;/SPAN&gt;).&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Mon, 20 Dec 2021 01:20:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-number-of-unique-part-of-string-from-log/m-p/578855#M201737</guid>
      <dc:creator>kamesjaci</dc:creator>
      <dc:date>2021-12-20T01:20:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to count number of unique part of string from log?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-number-of-unique-part-of-string-from-log/m-p/578907#M201758</link>
      <description>&lt;P&gt;Thanks this was helpfull/&lt;/P&gt;</description>
      <pubDate>Mon, 20 Dec 2021 12:24:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-number-of-unique-part-of-string-from-log/m-p/578907#M201758</guid>
      <dc:creator>jkauling</dc:creator>
      <dc:date>2021-12-20T12:24:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to count number of unique part of string from log?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-number-of-unique-part-of-string-from-log/m-p/579257#M201864</link>
      <description>&lt;P&gt;Kindly accept the answer, so it will be useful for other visitors.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Dec 2021 07:14:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-number-of-unique-part-of-string-from-log/m-p/579257#M201864</guid>
      <dc:creator>VatsalJagani</dc:creator>
      <dc:date>2021-12-26T07:14:18Z</dc:date>
    </item>
  </channel>
</rss>

