Split command in ruby by new line


(Sharon Sasporta) #1

Hi,

I am trying to split the message where ever a new line exist by ruby filter.

The command in the ruby code I use:

message_array = event.get('message').split("\n")

But the logstash doesn't start because of it.

It looks like logstash doesn't support the "\n"

message_array = event.get('message').split(\""}

Any workaround?

Regards,
Sharon.


(Magnus Bäck) #2

Don't mix single and double quotes inside the Ruby code. You can't use the same kind of quote that you're using the delimit the Ruby code block.


(Sharon Sasporta) #3

Sure, great.

So what should I do?

What do I need to do in order to split the event in new lines?

Thanks in advanced,
Sharon.


(Magnus Bäck) #4

As I said, use quotes consistently.

code => 'message_array = event.get("message").split("\n")'

Of course, to just split a string on newline characters you don't need a ruby filter, just use a mutate filter.


(Sharon Sasporta) #5

Thanks


(system) #6

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