# Extracting the last word of an event/line (Grok)

**URL:** <https://discuss.elastic.co/t/extracting-the-last-word-of-an-event-line-grok/214774>\
**Category:** Logstash\
**Created:** [January 13, 2020, 7:56am UTC](https://discuss.elastic.co/t/extracting-the-last-word-of-an-event-line-grok/214774 "2020-01-13T07:56:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nino](https://avatars.discourse-cdn.com/v4/letter/n/b9bd4f/32.png) [@nino](https://discuss.elastic.co/u/nino)\
**Post date:** [January 13, 2020, 7:56am UTC](https://discuss.elastic.co/t/extracting-the-last-word-of-an-event-line-grok/214774/1 "2020-01-13T07:56:21Z")

</div>

Hello all,

i am looking for a Grok pattern to retrieve the last word a matching line with literal.

#### input (file content)

`THISLINE 1,011.53EUR 12,815.50EUR 2,940.17 100,011.53EUR`

#### filter

grok{

```
      match => {
          message => ["(?<field>(?<=THISLINE )[^\r]*)" ]
     }

```

}

#### output

```
{
         "@version" => "1",
         "path" => "",
         "message" => " 1,011.53EUR 12,815.50EUR 2,940.17 100,011.53EUR",
         "@timestamp" => 2020-01-06T23:00:00.000Z
}

```

I need to extract the last word/number of the event and i've couldn't find a succesful pattern.

Best regards

---

<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:** [January 13, 2020, 1:38pm UTC](https://discuss.elastic.co/t/extracting-the-last-word-of-an-event-line-grok/214774/2 "2020-01-13T13:38:05Z")

</div>

> [@nino](#):
>
> "message" =\> " 1,011.53EUR 12,815.50EUR 2,940.17 100,011.53EUR",

What do you want to extract from that?

---

<div class="post-metadata">

**Author:** ![nino](https://avatars.discourse-cdn.com/v4/letter/n/b9bd4f/32.png) [@nino](https://discuss.elastic.co/u/nino)\
**Post date:** [January 13, 2020, 2:30pm UTC](https://discuss.elastic.co/t/extracting-the-last-word-of-an-event-line-grok/214774/3 "2020-01-13T14:30:43Z")

</div>

Sorry Badger, I forgot. The last quantity 100,011.53EUR. I've asked for a pattern because maybe it's more easy to extract the last quantity with a pattern that extract last word/number of an event/line. Sure It can be done using spliting the field and retrieve the part that i want pointing to the splited index. But i would to learn patterns and regular expresion to save lines of code.

`100,011.53EUR`

Best regards

---

<div class="post-metadata">

**Author:** ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)\
**Post date:** [January 13, 2020, 3:00pm UTC](https://discuss.elastic.co/t/extracting-the-last-word-of-an-event-line-grok/214774/4 "2020-01-13T15:00:50Z")

</div>

this will be badger's solution. he suggested to me on another thread.

ruby { code =\> " event.set('last\_field', event.get('message').split(' ').last)" }

---

<div class="post-metadata">

**Author:** ![nino](https://avatars.discourse-cdn.com/v4/letter/n/b9bd4f/32.png) [@nino](https://discuss.elastic.co/u/nino)\
**Post date:** [January 13, 2020, 3:04pm UTC](https://discuss.elastic.co/t/extracting-the-last-word-of-an-event-line-grok/214774/5 "2020-01-13T15:04:11Z")

</div>

Thank you so much elasticforme. I wonder if this can be done directly aplying a pattern or regular expresion to the event.

---

<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:** [February 10, 2020, 3:04pm UTC](https://discuss.elastic.co/t/extracting-the-last-word-of-an-event-line-grok/214774/6 "2020-02-10T15:04:16Z")

</div>

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