# How to get offset value using Logstash Filter

**URL:** <https://discuss.elastic.co/t/how-to-get-offset-value-using-logstash-filter/172248>\
**Category:** Logstash\
**Created:** [March 14, 2019, 5:23am UTC](https://discuss.elastic.co/t/how-to-get-offset-value-using-logstash-filter/172248 "2019-03-14T05:23:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sana1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sana1/32/46439_2.png) [@sana1](https://discuss.elastic.co/u/sana1)\
**Post date:** [March 14, 2019, 5:24am UTC](https://discuss.elastic.co/t/how-to-get-offset-value-using-logstash-filter/172248/1 "2019-03-14T05:24:00Z")

</div>

How to get offset value from a hex string "0b590b5900000000263efd95"  
say I want 0b printed in my new field "startmessage"

---

<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 14, 2019, 1:01pm UTC](https://discuss.elastic.co/t/how-to-get-offset-value-using-logstash-filter/172248/2 "2019-03-14T13:01:02Z")

</div>

If you want to replace a field with the first two characters of that field then you can use

```
mutate { gsub => ["hexValue", "^(..).*", "\1"] }

```

If you want to keep the original field then use mutate+add\_field to make a copy of the field first.

---

<div class="post-metadata">

**Author:** ![sana1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sana1/32/46439_2.png) [@sana1](https://discuss.elastic.co/u/sana1)\
**Post date:** [March 15, 2019, 6:24am UTC](https://discuss.elastic.co/t/how-to-get-offset-value-using-logstash-filter/172248/3 "2019-03-15T06:24:32Z")

</div>

If i want to get field after two characters like in the above string I want to get 59 only? whats the procedure?

---

<div class="post-metadata">

**Author:** ![sana1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sana1/32/46439_2.png) [@sana1](https://discuss.elastic.co/u/sana1)\
**Post date:** [March 15, 2019, 7:57am UTC](https://discuss.elastic.co/t/how-to-get-offset-value-using-logstash-filter/172248/4 "2019-03-15T07:57:19Z")

</div>

I did it with regex  
"^..(..).\*"

tell me syntax to retain the original value to be used further.

---

<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 15, 2019, 12:55pm UTC](https://discuss.elastic.co/t/how-to-get-offset-value-using-logstash-filter/172248/5 "2019-03-15T12:55:02Z")

</div>

> [@sana1](#):
>
> tell me syntax to retain the original value to be used further.

You can use mutate+add\_field or [mutate+copy](https://www.elastic.co/guide/en/logstash/current/plugins-filters-mutate.html#plugins-filters-mutate-copy).

---

<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 12, 2019, 12:55pm UTC](https://discuss.elastic.co/t/how-to-get-offset-value-using-logstash-filter/172248/6 "2019-04-12T12:55:05Z")

</div>

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