# How many times does a character appear?

**URL:** <https://discuss.elastic.co/t/how-many-times-does-a-character-appear/145454>\
**Category:** Logstash\
**Created:** [August 21, 2018, 7:57pm UTC](https://discuss.elastic.co/t/how-many-times-does-a-character-appear/145454 "2018-08-21T19:57:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JimP](https://avatars.discourse-cdn.com/v4/letter/j/8baadc/32.png) [@JimP](https://discuss.elastic.co/u/JimP)\
**Post date:** [August 21, 2018, 7:57pm UTC](https://discuss.elastic.co/t/how-many-times-does-a-character-appear/145454/1 "2018-08-21T19:57:15Z")

</div>

I would like to be able to find out how many times a character appears in a field. Is this possible with grok or some other filter?

To explain, we are getting beats from multiple sources, and multiple departments in my company. There is a standardized field, that has a delimiter character, which I use dissect its data. However, we have a new division that needs more information and wants to increase the amount of delimited data in this field. The issue I have is that the added information is an inside delimited value. The below is a quick example, where there is an extra value ( -loc- ) inside. And, of course there are very different rules for processing these.

My thought is to count how many dashes there are to know how to process. Is this doable in a Logstash filter (grok?), or is there another approach that I should consider?

For example:

div-dept-unit-app  
000-123-6589-652

div-dept-loc-unit-app  
000-123-112-6589-652

---

<div class="post-metadata">

**Author:** ![JimP](https://avatars.discourse-cdn.com/v4/letter/j/8baadc/32.png) [@JimP](https://discuss.elastic.co/u/JimP)\
**Post date:** [September 5, 2018, 1:16pm UTC](https://discuss.elastic.co/t/how-many-times-does-a-character-appear/145454/2 "2018-09-05T13:16:52Z")

</div>

Would the logstash kv filter be able to do this?

---

<div class="post-metadata">

**Author:** ![JimP](https://avatars.discourse-cdn.com/v4/letter/j/8baadc/32.png) [@JimP](https://discuss.elastic.co/u/JimP)\
**Post date:** [September 5, 2018, 6:54pm UTC](https://discuss.elastic.co/t/how-many-times-does-a-character-appear/145454/3 "2018-09-05T18:54:22Z")

</div>

```
filter {
  mutate {
    add_field => ["dotcount"]
  }
  
  ruby {
    code => "dotcount = message.count(\".\")"
  }
}
```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 3, 2018, 6:54pm UTC](https://discuss.elastic.co/t/how-many-times-does-a-character-appear/145454/4 "2018-10-03T18:54:24Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
