# Replace substring and concat rest

**URL:** https://discuss.elastic.co/t/replace-substring-and-concat-rest/237622
**Category:** Logstash
**Created:** [June 18, 2020, 11:25am UTC](https://discuss.elastic.co/t/replace-substring-and-concat-rest/237622 "2020-06-18T11:25:27Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![ksremo](https://avatars.discourse-cdn.com/v4/letter/k/5fc32e/32.png) [@ksremo](https://discuss.elastic.co/u/ksremo)
#### Post date: [June 18, 2020, 11:25am UTC](https://discuss.elastic.co/t/replace-substring-and-concat-rest/237622/1 "2020-06-18T11:25:28Z")

</div>

I have DNS Logs looks like

(14)xxxxxxxxxxxx(11)keydelivery(13)mediaservices(7)windows(3)net(0)  
(4)mediaservices(7)windows(3)net(0)  
(3)[windows.com](http://windows.com)(0)

I want to remove all (...) and replace this with a dot "."  
if (..) is in front or end of the string i want to remove it.

Any clever approach without doing that in more steps like first cut the values and then build a new field out of the substrings?

---

<div class="post-metadata">

### Author: ![Jenni](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jenni/32/29684_2.png) [@Jenni](https://discuss.elastic.co/u/Jenni)
#### Post date: [June 18, 2020, 12:32pm UTC](https://discuss.elastic.co/t/replace-substring-and-concat-rest/237622/2 "2020-06-18T12:32:26Z")

</div>

Something like this might work:

```
mutate {
  gsub => [
    "message", "(^\(\d*\))|(\(\d*\)$)", "",
    "message", "\(\d*\)", "."
  ]
}
```

---

<div class="post-metadata">

### Author: ![ksremo](https://avatars.discourse-cdn.com/v4/letter/k/5fc32e/32.png) [@ksremo](https://discuss.elastic.co/u/ksremo)
#### Post date: [June 18, 2020, 12:52pm UTC](https://discuss.elastic.co/t/replace-substring-and-concat-rest/237622/3 "2020-06-18T12:52:27Z")

</div>

Great help, thanks Jenni .... again 😉

---

<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 16, 2020, 12:52pm UTC](https://discuss.elastic.co/t/replace-substring-and-concat-rest/237622/4 "2020-07-16T12:52:30Z")

</div>

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