Extracting specific lines of a text using ruby

I am trying to extract only the lines 'My' from the message field.I am using a ruby code . The code runs fine when I am using it in a Ruby console but when I send it through logstash it does not extract the specific line

input {
file {
path => "/home/yasin/ruby/testdoc"
start_position => "beginning"
close_older => 0
sincedb_path => "/dev/null"
codec => multiline {
pattern => 'ZZZZZZ'
negate => true
what => previous

  		}                                                         

            } 

}

filter {
ruby {
code => "
str1 = event.get('message')
strlist1 = str1.split('\n')
strlist2 = strlist1.select{ |e| e.include? 'My'}
str2 = strlist2.join('\n')
event.set('my',str2)
"
}
}

output
{
elasticsearch {
hosts => "localhost:9200"
index => "mconfmy"
template_overwrite => true
}
stdout {
codec => rubydebug
}

}

Copy of sample data

ZZZZZZ
My name is anthony gonsalves
I am alone
happy
My pant is blue
ZZZZZZ
Why I am like this
My pizza
My Fame
ZZZZZZ
He is champ
My gift

I changed the quoutes from double to single and vice versa and it worked

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