# Specify a grok pattern to specific files?

**URL:** <https://discuss.elastic.co/t/specify-a-grok-pattern-to-specific-files/195360>\
**Category:** Logstash\
**Created:** [August 15, 2019, 2:37pm UTC](https://discuss.elastic.co/t/specify-a-grok-pattern-to-specific-files/195360 "2019-08-15T14:37:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![cjb312](https://avatars.discourse-cdn.com/v4/letter/c/b5ac83/32.png) [@cjb312](https://discuss.elastic.co/u/cjb312)\
**Post date:** [August 15, 2019, 2:37pm UTC](https://discuss.elastic.co/t/specify-a-grok-pattern-to-specific-files/195360/1 "2019-08-15T14:37:48Z")

</div>

Is there a way to specify a pattern to a specific file? For example I have a filter working for all byte\_count files. I want to add more filters for other files. How would I do this to match the file and pattern combination properly?

This is my current filter:  
filter {  
grok {  
match =\> { "message" =\> "%{NUMBER:ts}%{SPACE}%{NUMBER:ts\_delta}%{SPACE}%{IP:orig\_h}%{SPACE}%{INT:unique\_hosts}%{SPACE}%{INT:flows}%{SPACE}%{INT:bytes}%{SPACE}%{INT:flow\_avg}%{SPACE}%{INT:host\_avg}" }  
}  
}

---

<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 15, 2019, 2:49pm UTC](https://discuss.elastic.co/t/specify-a-grok-pattern-to-specific-files/195360/2 "2019-08-15T14:49:54Z")

</div>

Assuming your input adds the file name to the event (for example, the file input adds a path field to the event) you could use a [conditional](https://www.elastic.co/guide/en/logstash/current/event-dependent-configuration.html#conditionals) to decide whether to apply the filter.

---

<div class="post-metadata">

**Author:** ![cjb312](https://avatars.discourse-cdn.com/v4/letter/c/b5ac83/32.png) [@cjb312](https://discuss.elastic.co/u/cjb312)\
**Post date:** [August 15, 2019, 3:02pm UTC](https://discuss.elastic.co/t/specify-a-grok-pattern-to-specific-files/195360/3 "2019-08-15T15:02:20Z")

</div>

Ok that gives me a better idea after reading that but how would i compare my "byte\_count" file to?  
if path == byte\_count{}?

---

<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 15, 2019, 3:05pm UTC](https://discuss.elastic.co/t/specify-a-grok-pattern-to-specific-files/195360/4 "2019-08-15T15:05:29Z")

</div>

If you want to test whether byte\_count is part of the name you could use

```
if "byte_count" in [path] { ... }

```

Or you could do a regexp comparison

```
if [path] =~ /byte_count/ { ... }
```

---

<div class="post-metadata">

**Author:** ![cjb312](https://avatars.discourse-cdn.com/v4/letter/c/b5ac83/32.png) [@cjb312](https://discuss.elastic.co/u/cjb312)\
**Post date:** [August 15, 2019, 3:06pm UTC](https://discuss.elastic.co/t/specify-a-grok-pattern-to-specific-files/195360/5 "2019-08-15T15:06:32Z")

</div>

Ah that makes sense, thank you!

---

<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 12, 2019, 3:06pm UTC](https://discuss.elastic.co/t/specify-a-grok-pattern-to-specific-files/195360/6 "2019-09-12T15:06:37Z")

</div>

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