# Find and replace to a unicode string

**URL:** <https://discuss.elastic.co/t/find-and-replace-to-a-unicode-string/252226>\
**Category:** Logstash\
**Created:** [October 15, 2020, 3:35pm UTC](https://discuss.elastic.co/t/find-and-replace-to-a-unicode-string/252226 "2020-10-15T15:35:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew\_Harris](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrew_harris/32/77273_2.png) [@Andrew\_Harris](https://discuss.elastic.co/u/Andrew_Harris)\
**Post date:** [October 15, 2020, 3:35pm UTC](https://discuss.elastic.co/t/find-and-replace-to-a-unicode-string/252226/1 "2020-10-15T15:35:36Z")

</div>

Hi,

I am trying to do a find and replace using mutate to replace | (vertical bar) with Unicode u0001 (start of header) anywhere in the source message before being further parsed.

I have tried various combinations of forward slashes and back slashes but cannot get it to replace with the string "\u0001"

The code below replaces with double backslashes "\u0001"

```auto
    mutate {
         gsub => ["message", "\|", "\u0001"]
     }

```

---

<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:** [October 15, 2020, 10:11pm UTC](https://discuss.elastic.co/t/find-and-replace-to-a-unicode-string/252226/2 "2020-10-15T22:11:07Z")

</div>

The logstash configuration language does not provide a way to specify UTF-8 characters. You will need to use a ruby filter to do the gsub

```
ruby { code => 'event.set("message", event.get("message").gsub(/\|/, "\0001".encode("utf-8")))' }
```

---

<div class="post-metadata">

**Author:** ![Andrew\_Harris](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrew_harris/32/77273_2.png) [@Andrew\_Harris](https://discuss.elastic.co/u/Andrew_Harris)\
**Post date:** [October 22, 2020, 10:36am UTC](https://discuss.elastic.co/t/find-and-replace-to-a-unicode-string/252226/3 "2020-10-22T10:36:41Z")

</div>

That worked perfectly, thanks for your help!

---

<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:** [November 19, 2020, 10:36am UTC](https://discuss.elastic.co/t/find-and-replace-to-a-unicode-string/252226/4 "2020-11-19T10:36:44Z")

</div>

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