# Grok multiple date formats

**URL:** <https://discuss.elastic.co/t/grok-multiple-date-formats/190930>\
**Category:** Logstash\
**Created:** [July 17, 2019, 9:06am UTC](https://discuss.elastic.co/t/grok-multiple-date-formats/190930 "2019-07-17T09:06:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Regul](https://avatars.discourse-cdn.com/v4/letter/r/4bbf92/32.png) [@Regul](https://discuss.elastic.co/u/Regul)\
**Post date:** [July 17, 2019, 9:06am UTC](https://discuss.elastic.co/t/grok-multiple-date-formats/190930/1 "2019-07-17T09:06:42Z")

</div>

I'm trying to parse syslog messages from 2 sources at the moment, but they have different date formats:

```
 <12>Jul 16 14:37:33
 <30>2019:07:16-14:23:13

```

Right now I got the following:

```
<%{POSINT:syslog_pri}>%{YEAR}:%{MONTHNUM}:%{MONTHDAY}-%{HOUR}:?%{MINUTE}(?::?%{SECOND}) %{SYSLOGHOST:syslog_host} %{DATA:syslog_program}\[%{NUMBER:syslog_pid}\]\: %{GREEDYDATA:syslog_message}

<%{POSINT:syslog_pri}>%{MONTH} %{MONTHDAY} %{TIME} %{SYSLOGHOST:syslog_host} %{DATA:syslog_program}\[%{NUMBER:syslog_pid}\]\: %{GREEDYDATA:syslog_message}

```

Both these parse one of the formats.

I'm having a hard time to create the correct config so both of these formats are processed correctly.  
How can I combine these?

---

<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:** [July 17, 2019, 1:10pm UTC](https://discuss.elastic.co/t/grok-multiple-date-formats/190930/2 "2019-07-17T13:10:10Z")

</div>

You should be able to do alternation using |

```
<%{POSINT:syslog_pri}>(%{YEAR}:%{MONTHNUM}:%{MONTHDAY}-%{HOUR}:?%{MINUTE}(?::?%{SECOND})|%{MONTH} %{MONTHDAY} %{TIME}) %{SYSLOGHOST:syslog_host} %{DATA:syslog_program}\[%{NUMBER:syslog_pid}\]\: %{GREEDYDATA:syslog_message}
```

---

<div class="post-metadata">

**Author:** ![Regul](https://avatars.discourse-cdn.com/v4/letter/r/4bbf92/32.png) [@Regul](https://discuss.elastic.co/u/Regul)\
**Post date:** [July 22, 2019, 10:15am UTC](https://discuss.elastic.co/t/grok-multiple-date-formats/190930/3 "2019-07-22T10:15:00Z")

</div>

Perfect! That does the trick.

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:** [August 19, 2019, 10:15am UTC](https://discuss.elastic.co/t/grok-multiple-date-formats/190930/4 "2019-08-19T10:15:02Z")

</div>

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