Knowledge Management

How many distinctly different characters are in a word?

automayt
Explorer

I have a field with strings and I want to calculate the amount of distinctly different characters that appear in the strings. For instance
rabbit - 5
Fox - 3
TabbYCaT - 5
Raptor - 6

I'd considered splitting every word and doing something like len(values()) but surely there is a more efficient way.

Tags (1)
0 Karma
1 Solution

jpolvino
Builder

Here is one way to do it:

| makeresults 
| eval album="abacab"
| makemv tokenizer="(.)" album
| eval album=mvdedup(album)
| eval c=mvcount(album)

This returns 3, which is the number of unique characters in the field named "album".

View solution in original post

0 Karma

vnravikumar
Champion

Hi

Try this

| makeresults 
| eval test="rabbit,Fox,TabbYCaT,Raptor" |makemv delim="," test|mvexpand test
| eval result = mvcount(mvdedup(split(test,"")))
0 Karma

jpolvino
Builder

Here is one way to do it:

| makeresults 
| eval album="abacab"
| makemv tokenizer="(.)" album
| eval album=mvdedup(album)
| eval c=mvcount(album)

This returns 3, which is the number of unique characters in the field named "album".

0 Karma
Get Updates on the Splunk Community!

Splunk Mobile: Your Brand-New Home Screen

Meet Your New Mobile Hub  Hello Splunk Community!  Staying connected to your data—no matter where you are—is ...

Introducing Value Insights (Beta): Understand the Business Impact your organization ...

Real progress on your strategic priorities starts with knowing the business outcomes your teams are delivering ...

Enterprise Security (ES) Essentials 8.3 is Now GA — Smarter Detections, Faster ...

As of today, Enterprise Security (ES) Essentials 8.3 is now generally available, helping SOC teams simplify ...