# How to remove the last byte from an IP address?

**URL:** <https://discuss.elastic.co/t/how-to-remove-the-last-byte-from-an-ip-address/219241>\
**Category:** Logstash\
**Created:** [February 13, 2020, 3:38pm UTC](https://discuss.elastic.co/t/how-to-remove-the-last-byte-from-an-ip-address/219241 "2020-02-13T15:38:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aleksandra\_Minko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aleksandra_minko/32/45836_2.png) [@Aleksandra\_Minko](https://discuss.elastic.co/u/Aleksandra_Minko)\
**Post date:** [February 13, 2020, 3:38pm UTC](https://discuss.elastic.co/t/how-to-remove-the-last-byte-from-an-ip-address/219241/1 "2020-02-13T15:38:56Z")

</div>

Hello,

I have a NetFlow field named **[flow][addr]** which represents an IP address.

For example **[flow][addr]** looks like: **10.96.31.41**.

I would like to remove the last **Byte** of my field and keep only **10.96.31**. I also would like to save the value in a new field called for example **[flow][pref]**.

Please help ! Thank you.  
Aleksandra

---

<div class="post-metadata">

**Author:** ![Aleksandra\_Minko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aleksandra_minko/32/45836_2.png) [@Aleksandra\_Minko](https://discuss.elastic.co/u/Aleksandra_Minko)\
**Post date:** [February 14, 2020, 2:21pm UTC](https://discuss.elastic.co/t/how-to-remove-the-last-byte-from-an-ip-address/219241/2 "2020-02-14T14:21:31Z")

</div>

Found the answer :

filter {  
if[flow][dst\_addr]{  
mutate{  
id =\> "netflow\_9\_convert\_addr\_to\_prefix"  
add\_field =\> { "[flow][dst\_prefix]" =\> "%{[flow][dst\_addr]}" }  
}  
mutate{  
id =\> "netflow\_9\_trim\_addr"  
gsub =\> ["[flow][dst\_prefix]", ".(?:\d{1,3}$)", " "]  
}  
}  
}

---

<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:** [March 13, 2020, 2:21pm UTC](https://discuss.elastic.co/t/how-to-remove-the-last-byte-from-an-ip-address/219241/3 "2020-03-13T14:21:36Z")

</div>

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