# Extracting specific lines of a text using ruby

**URL:** <https://discuss.elastic.co/t/extracting-specific-lines-of-a-text-using-ruby/175134>\
**Category:** Logstash\
**Created:** [April 3, 2019, 8:35am UTC](https://discuss.elastic.co/t/extracting-specific-lines-of-a-text-using-ruby/175134 "2019-04-03T08:35:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yasin\_mohammed](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yasin_mohammed/32/64406_2.png) [@yasin\_mohammed](https://discuss.elastic.co/u/yasin_mohammed)\
**Post date:** [April 3, 2019, 8:35am UTC](https://discuss.elastic.co/t/extracting-specific-lines-of-a-text-using-ruby/175134/1 "2019-04-03T08:35:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![yasin\_mohammed](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yasin_mohammed/32/64406_2.png) [@yasin\_mohammed](https://discuss.elastic.co/u/yasin_mohammed)\
**Post date:** [April 3, 2019, 9:47am UTC](https://discuss.elastic.co/t/extracting-specific-lines-of-a-text-using-ruby/175134/2 "2019-04-03T09:47:51Z")

</div>

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

---

<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:** [May 1, 2019, 9:56am UTC](https://discuss.elastic.co/t/extracting-specific-lines-of-a-text-using-ruby/175134/3 "2019-05-01T09:56:38Z")

</div>

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