# Remove the last character of a string field

**URL:** <https://discuss.elastic.co/t/remove-the-last-character-of-a-string-field/197691>\
**Category:** Logstash\
**Created:** [September 2, 2019, 1:08pm UTC](https://discuss.elastic.co/t/remove-the-last-character-of-a-string-field/197691 "2019-09-02T13:08:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![saisimo02](https://avatars.discourse-cdn.com/v4/letter/s/edb3f5/32.png) [@saisimo02](https://discuss.elastic.co/u/saisimo02)\
**Post date:** [September 2, 2019, 1:08pm UTC](https://discuss.elastic.co/t/remove-the-last-character-of-a-string-field/197691/1 "2019-09-02T13:08:35Z")

</div>

Hello,

I have a string field named **hostname** , when the user have multiple instances I am getting an index in this field.

For example **hostname** looks like: **toto1940,toto1941,toto1942**.

I would like to remove the last element of my field and getting only **toto194**

Thanks for help

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [September 2, 2019, 1:32pm UTC](https://discuss.elastic.co/t/remove-the-last-character-of-a-string-field/197691/2 "2019-09-02T13:32:38Z")

</div>

If that is a string you could do it using

```
dissect { mapping => { "message" => "%{host}0,%{}" } }
```

---

<div class="post-metadata">

**Author:** ![saisimo02](https://avatars.discourse-cdn.com/v4/letter/s/edb3f5/32.png) [@saisimo02](https://discuss.elastic.co/u/saisimo02)\
**Post date:** [September 2, 2019, 3:11pm UTC](https://discuss.elastic.co/t/remove-the-last-character-of-a-string-field/197691/3 "2019-09-02T15:11:47Z")

</div>

Thank you Badger,

I resolved it by using ruby:

```
ruby {
code => "
   event.set('myhostname', event.get('hostname')[0..-2])
       "
    }
```

---

<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:** [September 30, 2019, 3:13pm UTC](https://discuss.elastic.co/t/remove-the-last-character-of-a-string-field/197691/4 "2019-09-30T15:13:45Z")

</div>

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