# Extract domain from field

**URL:** <https://discuss.elastic.co/t/extract-domain-from-field/150541>\
**Category:** Logstash\
**Created:** [October 1, 2018, 9:39am UTC](https://discuss.elastic.co/t/extract-domain-from-field/150541 "2018-10-01T09:39:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![elk2](https://avatars.discourse-cdn.com/v4/letter/e/f14d63/32.png) [@elk2](https://discuss.elastic.co/u/elk2)\
**Post date:** [October 1, 2018, 9:39am UTC](https://discuss.elastic.co/t/extract-domain-from-field/150541/1 "2018-10-01T09:39:23Z")

</div>

I want to extract domain from email field that is like this:

`smtp.from_mail : "news <newsletters@example.com>"`

I would like to use grok or other useful plugin.

---

<div class="post-metadata">

**Author:** ![elk2](https://avatars.discourse-cdn.com/v4/letter/e/f14d63/32.png) [@elk2](https://discuss.elastic.co/u/elk2)\
**Post date:** [October 2, 2018, 10:14am UTC](https://discuss.elastic.co/t/extract-domain-from-field/150541/2 "2018-10-02T10:14:18Z")

</div>

Someone can help me?

---

<div class="post-metadata">

**Author:** ![bardie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bardie/32/36173_2.png) [@bardie](https://discuss.elastic.co/u/bardie)\
**Post date:** [October 3, 2018, 12:57pm UTC](https://discuss.elastic.co/t/extract-domain-from-field/150541/3 "2018-10-03T12:57:44Z")

</div>

`smtp.from_mail : "news \<%{DATA:user}\@%{DATA:domain}\>"`

on logstash use

```
  grok {
    match => ['message', 'smtp.from_mail : "news \<%{DATA:user}\@%{DATA:domain}\>"']
  }

```

You can build or test your own grok statements on:

[https://grokdebug.herokuapp.com/](https://grokdebug.herokuapp.com/) or Kibana Grok plugin

---

<div class="post-metadata">

**Author:** ![elk2](https://avatars.discourse-cdn.com/v4/letter/e/f14d63/32.png) [@elk2](https://discuss.elastic.co/u/elk2)\
**Post date:** [October 5, 2018, 1:34pm UTC](https://discuss.elastic.co/t/extract-domain-from-field/150541/4 "2018-10-05T13:34:34Z")

</div>

> [@bardie](#):
>
> @%{DATA:domain}&gt;

Thanks for your reply,  
I tried but when I try to print the field domain with stdout plugin it seems don't work..

> output{  
> if [event] == "smtp" {  
> stdout {  
> codec =\> line { format =\>"%{[smtp][from]} - %{[domain]} - %{maildomain} - %[maildomain] - %maildomain" }  
> }  
> }

I see this results  
[test@example.com](mailto:test@example.com) - %{[domain]} - %{domain} - %[domain] - %domain

I tried all combinations to print domain but without success.

---

<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 2, 2018, 2:01pm UTC](https://discuss.elastic.co/t/extract-domain-from-field/150541/6 "2018-11-02T14:01:03Z")

</div>

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