# Grok - extract file extension from file name

**URL:** <https://discuss.elastic.co/t/grok-extract-file-extension-from-file-name/102528>\
**Category:** Logstash\
**Created:** [October 3, 2017, 8:38am UTC](https://discuss.elastic.co/t/grok-extract-file-extension-from-file-name/102528 "2017-10-03T08:38:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![evild3ad](https://avatars.discourse-cdn.com/v4/letter/e/e47774/32.png) [@evild3ad](https://discuss.elastic.co/u/evild3ad)\
**Post date:** [October 3, 2017, 8:38am UTC](https://discuss.elastic.co/t/grok-extract-file-extension-from-file-name/102528/1 "2017-10-03T08:38:39Z")

</div>

Hi,

I have problems with creating a grok filter to extract the file extension from the file name field.

Example data:  
9151\_to\_9152.log  
80bddb9998f9f66bc44b59d9899bbbb853b8958ecd9188e14fd0828e00246050.txt ($FILE\_NAME)

I tried:  
(.(?[^./]+))

But I don't want to have "($FILE\_NAME)"...only the file extension.

Thanks!

---

<div class="post-metadata">

**Author:** ![evild3ad](https://avatars.discourse-cdn.com/v4/letter/e/e47774/32.png) [@evild3ad](https://discuss.elastic.co/u/evild3ad)\
**Post date:** [October 3, 2017, 9:38am UTC](https://discuss.elastic.co/t/grok-extract-file-extension-from-file-name/102528/2 "2017-10-03T09:38:30Z")

</div>

(.(?[0-9A-Za-z]\*))

---

<div class="post-metadata">

**Author:** ![evild3ad](https://avatars.discourse-cdn.com/v4/letter/e/e47774/32.png) [@evild3ad](https://discuss.elastic.co/u/evild3ad)\
**Post date:** [October 3, 2017, 1:51pm UTC](https://discuss.elastic.co/t/grok-extract-file-extension-from-file-name/102528/3 "2017-10-03T13:51:48Z")

</div>

Hm...but here is it still not working:

Apps - Process All.pas.0001.bak

Any idea?

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [October 3, 2017, 2:15pm UTC](https://discuss.elastic.co/t/grok-extract-file-extension-from-file-name/102528/4 "2017-10-03T14:15:46Z")

</div>

Make sure you escape the period and add a `$` anchor at the end so you only match alphanumerical sequences at the end of the string.

---

<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:** [October 31, 2017, 2:15pm UTC](https://discuss.elastic.co/t/grok-extract-file-extension-from-file-name/102528/5 "2017-10-31T14:15:51Z")

</div>

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