# Use gsub to add points to an integer

**URL:** <https://discuss.elastic.co/t/use-gsub-to-add-points-to-an-integer/221901>\
**Category:** Logstash\
**Created:** [March 3, 2020, 2:38pm UTC](https://discuss.elastic.co/t/use-gsub-to-add-points-to-an-integer/221901 "2020-03-03T14:38:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![opellulo](https://avatars.discourse-cdn.com/v4/letter/o/e19adc/32.png) [@opellulo](https://discuss.elastic.co/u/opellulo)\
**Post date:** [March 3, 2020, 2:38pm UTC](https://discuss.elastic.co/t/use-gsub-to-add-points-to-an-integer/221901/1 "2020-03-03T14:38:20Z")

</div>

Hi all,  
In my data stream i have a "price" value that however is an integer (1399 for 13.99 and so on). I want to convert it to ease the visualization but i can't find any valid numeral.js option in Kibana so i though of adding a new field during the Logstash pipeline, something like this:

```
  mutate {
    copy => { "[Price]" => "[PriceCent]" }
  }
  mutate {
    gsub => ["[PriceCent]", "\d{2}$", "\.\d{2}$" ]
  }

```

However it isn't working. Am I missing something in the regex or I have to rethink all the process?  
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:** [March 3, 2020, 3:02pm UTC](https://discuss.elastic.co/t/use-gsub-to-add-points-to-an-integer/221901/2 "2020-03-03T15:02:24Z")

</div>

You would need to use a capture group and reference it in the replacement.

---

<div class="post-metadata">

**Author:** ![opellulo](https://avatars.discourse-cdn.com/v4/letter/o/e19adc/32.png) [@opellulo](https://discuss.elastic.co/u/opellulo)\
**Post date:** [March 4, 2020, 9:26am UTC](https://discuss.elastic.co/t/use-gsub-to-add-points-to-an-integer/221901/3 "2020-03-04T09:26:22Z")

</div>

In the end I solved the issue with another logic:

```
grok {
    match => {"[Price]" => "(?<units>\d*)(?<cents>\d{2})$"}
  }
 mutate {
    add_field => {
      "[PriceCent]" => "%{units},%{cents}"}
}

```

However i still do not grasp how to use gsub.

---

<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:** [March 4, 2020, 6:17pm UTC](https://discuss.elastic.co/t/use-gsub-to-add-points-to-an-integer/221901/4 "2020-03-04T18:17:07Z")

</div>

> [@opellulo](#):
>
> However i still do not grasp how to use gsub.

```
mutate { gsub => ["[PriceCent]", "(\d{2})$", "\.\1" ] }

```

---

<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:** [April 1, 2020, 6:17pm UTC](https://discuss.elastic.co/t/use-gsub-to-add-points-to-an-integer/221901/5 "2020-04-01T18:17:10Z")

</div>

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