# Grok Filter Parse a Hyphen as absent

**URL:** <https://discuss.elastic.co/t/grok-filter-parse-a-hyphen-as-absent/106030>\
**Category:** Logstash\
**Created:** [November 1, 2017, 12:49pm UTC](https://discuss.elastic.co/t/grok-filter-parse-a-hyphen-as-absent/106030 "2017-11-01T12:49:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ewan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ewan/32/23645_2.png) [@Ewan](https://discuss.elastic.co/u/Ewan)\
**Post date:** [November 1, 2017, 12:49pm UTC](https://discuss.elastic.co/t/grok-filter-parse-a-hyphen-as-absent/106030/1 "2017-11-01T12:49:35Z")

</div>

Hi,  
I'm trying to parse a log which will insert a hyphen for some fields when there is no value:

Is there an easy way with grok to treat the hyphen as if the value is absent? i.e. not add the hyphen as a value, but continue to parse the rest of the values correctly?

2 Example lines from log:  
2017-11-01 12:03:47 - - - "-" 10.0.0.100 "-" - "-" - "VS: name"  
2017-11-01 12:44:01 10.0.0.1 "/file.cfc?test=thing" 192.168.1.1:80 192.168.1.1:80 "P: pool1" 10.0.0.100 "thing1=24; thing2=5;" 200 "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36" 2 "VS: name"

Current filter:  
%{TIMESTAMP\_ISO8601:log\_timestamp} %{DATA:TrueClientIP} (%{DATA:RequestPath})? %{DATA:Node} %{DATA:RequiredNode} %{QUOTEDSTRING:Pool} %{IPV4:RequestIP} %{QUOTEDSTRING:Cookie} %{DATA:StatusCode} %{QUOTEDSTRING:UserAgent} %{DATA:Hops} %{QUOTEDSTRING:VirtualServer}

I am very new to grok and appreciate my filter is probably wrong in many ways and I welcome any constructive criticism.

Thanks,  
Ewan.

---

<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:** [November 1, 2017, 3:36pm UTC](https://discuss.elastic.co/t/grok-filter-parse-a-hyphen-as-absent/106030/2 "2017-11-01T15:36:59Z")

</div>

Use `(-|%{PATTERN:fieldname})` to match either a hyphen or PATTERN, and in the latter case store the result in `fieldname`.

You're overusing DATA. That can result in extremely poor performance or surprising matches. Use more exact patterns whenever possible.

---

<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:** [November 29, 2017, 3:37pm UTC](https://discuss.elastic.co/t/grok-filter-parse-a-hyphen-as-absent/106030/3 "2017-11-29T15:37:24Z")

</div>

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