# Create field form file name

**URL:** <https://discuss.elastic.co/t/create-field-form-file-name/266846>\
**Category:** Logstash\
**Created:** [March 10, 2021, 5:30pm UTC](https://discuss.elastic.co/t/create-field-form-file-name/266846 "2021-03-10T17:30:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ManuelF](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@ManuelF](https://discuss.elastic.co/u/ManuelF)\
**Post date:** [March 10, 2021, 5:30pm UTC](https://discuss.elastic.co/t/create-field-form-file-name/266846/1 "2021-03-10T17:30:08Z")

</div>

Hi,

Note: Running ELK 7.10.1

I am trying to generate a new field using Grok, by extracting data from the file name.

File name comes from "`path`".

`path => "/opt/app_logs/*.log"`

Example:

`ip_block-hgTest.Dev1test-2021-03-10_09_10.log`

Grok filter:

```
grok {
    match => { "path" => "ip_block-%{HOSTNAME:Device}-%{DATA}.log" }
    tag_on_failure => []
}

```

Result:

`hgTest.Dev1test-2021-03`

The result it's almost what I need, but for some reason is including part of the date next to the hostname.

The desired result should be just: `hgTest.Dev1test`

Any idea about what could I be doing wrong?

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [March 10, 2021, 5:54pm UTC](https://discuss.elastic.co/t/create-field-form-file-name/266846/2 "2021-03-10T17:54:38Z")

</div>

The [regex](https://github.com/hpcugent/logstash-patterns/blob/master/files/grok-patterns#L32) for `HOSTNAME` doesn't work for that format in your data. You can see that [here](https://regex101.com/r/4d6VQ2/1).

If you can't find another pattern that will work then just `ip_block-%{DATA:Device}-%{DATA:Date}.log` will.

---

<div class="post-metadata">

**Author:** ![ManuelF](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@ManuelF](https://discuss.elastic.co/u/ManuelF)\
**Post date:** [March 10, 2021, 7:01pm UTC](https://discuss.elastic.co/t/create-field-form-file-name/266846/3 "2021-03-10T19:01:47Z")

</div>

Thank you @aaron-nimocks . Solution provided worked like charm!! 😋 👍

Cheers!!

---

<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 7, 2021, 7:02pm UTC](https://discuss.elastic.co/t/create-field-form-file-name/266846/4 "2021-04-07T19:02:22Z")

</div>

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