# Extract file name and add as a field

**URL:** <https://discuss.elastic.co/t/extract-file-name-and-add-as-a-field/282105>\
**Category:** Logstash\
**Created:** [August 20, 2021, 5:32pm UTC](https://discuss.elastic.co/t/extract-file-name-and-add-as-a-field/282105 "2021-08-20T17:32:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sherabu](https://avatars.discourse-cdn.com/v4/letter/s/b38774/32.png) [@Sherabu](https://discuss.elastic.co/u/Sherabu)\
**Post date:** [August 20, 2021, 5:32pm UTC](https://discuss.elastic.co/t/extract-file-name-and-add-as-a-field/282105/1 "2021-08-20T17:32:09Z")

</div>

Hi bro and sis

I will be sending file from filebeat to logstash. Is there a way I can extract file name on logstash filter? I want to add as a new field

My file name  
Path/sample.log  
Path/sample.20210821

Your small advice and example is big help to me

---

<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:** [August 21, 2021, 4:21pm UTC](https://discuss.elastic.co/t/extract-file-name-and-add-as-a-field/282105/2 "2021-08-21T16:21:43Z")

</div>

There are many ways to do this. See [here](https://discuss.elastic.co/t/logtash-adding-filename-as-index-name/131487/2) and [here](https://discuss.elastic.co/t/one-or-more-inputs-to-one-or-more-outputs/171906/6) for examples.

---

<div class="post-metadata">

**Author:** ![Sherabu](https://avatars.discourse-cdn.com/v4/letter/s/b38774/32.png) [@Sherabu](https://discuss.elastic.co/u/Sherabu)\
**Post date:** [August 21, 2021, 5:30pm UTC](https://discuss.elastic.co/t/extract-file-name-and-add-as-a-field/282105/3 "2021-08-21T17:30:50Z")

</div>

I tried as below

````auto
```
filter {
  grok {
    match => ["path","%{GREEDYDATA}/%{GREEDYDATA:filename}\.log"]
  }
}
```

````

But in filename field it giving .log .how to have only name without extension?

---

<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:** [September 18, 2021, 5:31pm UTC](https://discuss.elastic.co/t/extract-file-name-and-add-as-a-field/282105/4 "2021-09-18T17:31:42Z")

</div>

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