# Adding a new field from multiple fields and including a newline

**URL:** <https://discuss.elastic.co/t/adding-a-new-field-from-multiple-fields-and-including-a-newline/68418>\
**Category:** Logstash\
**Created:** [December 8, 2016, 10:36am UTC](https://discuss.elastic.co/t/adding-a-new-field-from-multiple-fields-and-including-a-newline/68418 "2016-12-08T10:36:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![elvarb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elvarb/32/44840_2.png) [@elvarb](https://discuss.elastic.co/u/elvarb)\
**Post date:** [December 8, 2016, 10:36am UTC](https://discuss.elastic.co/t/adding-a-new-field-from-multiple-fields-and-including-a-newline/68418/1 "2016-12-08T10:36:23Z")

</div>

I have an event with multiple fields and I want to create a new summary field with specific details but also want to add the newline character in that field. No matter what I try the add\_field option in mutate does not want to convert \n to a newline. Is there some way to do this?

For example

```
	mutate {
		add_field => { 
			"email" => "%{mailbox} \n %{date}"
		}
	}
```

---

<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:** [December 12, 2016, 6:35am UTC](https://discuss.elastic.co/t/adding-a-new-field-from-multiple-fields-and-including-a-newline/68418/2 "2016-12-12T06:35:19Z")

</div>

Strings in the Logstash configuration have no generic support for escape sequences. I suspect you'll have to use a ruby filter to generate the string instead, perhaps something like this (assuming Logstash 2.4 or later):

```nohighlight
ruby {
  code => "event.set('email', event.get('mailbox') + ' ' + 10.chr + ' ' + event.get('date'))"
}

```

---

<div class="post-metadata">

**Author:** ![elvarb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elvarb/32/44840_2.png) [@elvarb](https://discuss.elastic.co/u/elvarb)\
**Post date:** [December 12, 2016, 4:06pm UTC](https://discuss.elastic.co/t/adding-a-new-field-from-multiple-fields-and-including-a-newline/68418/3 "2016-12-12T16:06:41Z")

</div>

Thanks, that worked!

I have had to use Ruby so much lately that it's crazy. Logstash 5+ seems to be having huge issues with character encoding, going to gather my notes and create a ticket tomorrow.

---

<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:** [January 9, 2017, 4:06pm UTC](https://discuss.elastic.co/t/adding-a-new-field-from-multiple-fields-and-including-a-newline/68418/4 "2017-01-09T16:06:44Z")

</div>

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