# Match and extract last part of log in pipe delimited log

**URL:** https://discuss.elastic.co/t/match-and-extract-last-part-of-log-in-pipe-delimited-log/90086
**Category:** Logstash
**Created:** [June 20, 2017, 11:13am UTC](https://discuss.elastic.co/t/match-and-extract-last-part-of-log-in-pipe-delimited-log/90086 "2017-06-20T11:13:25Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Pranav1](https://avatars.discourse-cdn.com/v4/letter/p/f6c823/32.png) [@Pranav1](https://discuss.elastic.co/u/Pranav1)
#### Post date: [June 20, 2017, 11:13am UTC](https://discuss.elastic.co/t/match-and-extract-last-part-of-log-in-pipe-delimited-log/90086/1 "2017-06-20T11:13:25Z")

</div>

Logstash is receving following log -  
**\> Timestamp|Field1|Field2|...|Field n|Log message**

The number of fields is varaible and not fixed.  
My goal is to extract just the Timestamp and Log message and add it as a new key value pair in the document as shown below-

> {  
> "Timestamp": "2017-06-15T09:39:02.619Z",  
> "message": "Log message"  
> }

I tried using grok filter. I can get the timestamp using its 'match' option.

> grok {  
> match =\> { "message" =\> "%{TIMESTAMP\_ISO8601:Timestamp}" }  
> }

**But I am unable to match the log message as the fields in between are variable.**

Is it possible to do this using grok filter or can any other filter help?

---

<div class="post-metadata">

### Author: ![guyboertje](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guyboertje/32/31592_2.png) [@guyboertje](https://discuss.elastic.co/u/guyboertje)
#### Post date: [June 20, 2017, 11:42am UTC](https://discuss.elastic.co/t/match-and-extract-last-part-of-log-in-pipe-delimited-log/90086/2 "2017-06-20T11:42:16Z")

</div>

Grok should be fine.  
After the `%{TIMESTAMP_ISO8601:Timestamp}\|` allow for the first pipe, then allow for a variable number of `([^|]+\|)+` then the message `%{GREEDYDATA:message}`

See [http://grokconstructor.appspot.com/do/match](http://grokconstructor.appspot.com/do/match)  
I used this Grok pattern

```auto
%{TIMESTAMP_ISO8601:Timestamp}\|(?:[^|]+\|)+%{GREEDYDATA:msg}

```

I used these lines

```auto
2017-06-15T09:39:02.619Z|A|B|C|D|E|this is a long message
2017-06-15T09:39:04.619Z|A|B|E|this is a second long message

```

I got this result

```auto
2017-06-15T09:39:02.619Z|A|B|C|D|E|this is a long message
MATCHED
Timestamp 2017-06-15T09:39:02.619Z
msg this·is·a·long·message
2017-06-15T09:39:04.619Z|A|B|E|this is a second long message
MATCHED
Timestamp 2017-06-15T09:39:04.619Z
msg this·is·a·second·long·message

```

---

<div class="post-metadata">

### Author: ![Pranav1](https://avatars.discourse-cdn.com/v4/letter/p/f6c823/32.png) [@Pranav1](https://discuss.elastic.co/u/Pranav1)
#### Post date: [June 21, 2017, 2:54pm UTC](https://discuss.elastic.co/t/match-and-extract-last-part-of-log-in-pipe-delimited-log/90086/3 "2017-06-21T14:54:19Z")

</div>

Thanks a lot Guy. It helped me.

---

<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: [July 19, 2017, 2:54pm UTC](https://discuss.elastic.co/t/match-and-extract-last-part-of-log-in-pipe-delimited-log/90086/4 "2017-07-19T14:54:33Z")

</div>

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