# Struggling to replace a string in a syslog message with sub

**URL:** <https://discuss.elastic.co/t/struggling-to-replace-a-string-in-a-syslog-message-with-sub/307809>\
**Category:** Logstash\
**Created:** [June 21, 2022, 10:49pm UTC](https://discuss.elastic.co/t/struggling-to-replace-a-string-in-a-syslog-message-with-sub/307809 "2022-06-21T22:49:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ddaloia](https://avatars.discourse-cdn.com/v4/letter/d/ecccb3/32.png) [@ddaloia](https://discuss.elastic.co/u/ddaloia)\
**Post date:** [June 21, 2022, 10:49pm UTC](https://discuss.elastic.co/t/struggling-to-replace-a-string-in-a-syslog-message-with-sub/307809/1 "2022-06-21T22:49:25Z")

</div>

Hi Friends. I am taking in cef syslog messages from an application called Secret Server. The messages are not parsing correctly because some of the fields usernames have a slash in the username. The format is domain\username.

I am trying to use mutate to remove the domain\ from the username field and failing.

Is there a reason this filter wouldn't work?

```auto
filter {
  mutate { gsub => ["message","domain\\",""]
  }
}

```

---

<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:** [June 22, 2022, 12:26am UTC](https://discuss.elastic.co/t/struggling-to-replace-a-string-in-a-syslog-message-with-sub/307809/2 "2022-06-22T00:26:31Z")

</div>

Is there really a square bracket in the [message] field? Please format your configuration. Edit your post, select the filter {} section, and click on \</\> in the toolbar above the edit pane.

---

<div class="post-metadata">

**Author:** ![ddaloia](https://avatars.discourse-cdn.com/v4/letter/d/ecccb3/32.png) [@ddaloia](https://discuss.elastic.co/u/ddaloia)\
**Post date:** [June 22, 2022, 11:00am UTC](https://discuss.elastic.co/t/struggling-to-replace-a-string-in-a-syslog-message-with-sub/307809/3 "2022-06-22T11:00:25Z")

</div>

Apologies, it did not render correctly. I added the code symbols and the message looks correct now.

Thanks!

---

<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:** [June 22, 2022, 4:54pm UTC](https://discuss.elastic.co/t/struggling-to-replace-a-string-in-a-syslog-message-with-sub/307809/4 "2022-06-22T16:54:25Z")

</div>

OK, it is an oddity of the configuration compiler that you cannot escape a backslash at the end of a string. The backslash always escapes the closing double quote. The standard workaround for this is to use a character group that evaluates to one occurrence of a backslash.

```
mutate { gsub => ["message","domain[\\]",""]

```

---

<div class="post-metadata">

**Author:** ![ddaloia](https://avatars.discourse-cdn.com/v4/letter/d/ecccb3/32.png) [@ddaloia](https://discuss.elastic.co/u/ddaloia)\
**Post date:** [June 23, 2022, 10:36pm UTC](https://discuss.elastic.co/t/struggling-to-replace-a-string-in-a-syslog-message-with-sub/307809/5 "2022-06-23T22:36:45Z")

</div>

Thanks Badger for your help. This had some unexpected results as well. I am going to review my side a little bit more to see if can understand what I am seeing now. Appreciate the 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:** [July 21, 2022, 10:37pm UTC](https://discuss.elastic.co/t/struggling-to-replace-a-string-in-a-syslog-message-with-sub/307809/6 "2022-07-21T22:37:26Z")

</div>

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