# Grep a block of code

**URL:** <https://www.ruby-forum.com/t/grep-a-block-of-code/167397>\
**Category:** Ruby\
**Created:** [May 7, 2009, 1:35pm UTC](https://www.ruby-forum.com/t/grep-a-block-of-code/167397 "2009-05-07T13:35:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![beny18241](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbce88/32.png) [@beny18241](https://www.ruby-forum.com/u/beny18241)\
**Post date:** [May 7, 2009, 1:35pm UTC](https://www.ruby-forum.com/t/grep-a-block-of-code/167397/1 "2009-05-07T13:35:07Z")

</div>

Hi

Lately someone gave me a task, to grep from csv file but a block of  
code.  
How to do it ?

for example

2 3 4 5

How to use grep to give me all form file wich start with and end  
with

I’ve tried that way…

puts File.readlines(ARGV[0]).grep(/ \* \</tag\>/)

Please help

---

<div class="post-metadata">

**Author:** ![beny18241](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbce88/32.png) [@beny18241](https://www.ruby-forum.com/u/beny18241)\
**Post date:** [May 7, 2009, 2:05pm UTC](https://www.ruby-forum.com/t/grep-a-block-of-code/167397/2 "2009-05-07T14:05:28Z")

</div>

From: “Maciej Pindela” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> I’ve tried that way…
> 
> puts File.readlines(ARGV[0]).grep(/ \* \</tag\>/)

puts ARGF.read.scan(/.\*?\</tag\>/m)

Regards,

Bill

---

<div class="post-metadata">

**Author:** ![beny18241](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbce88/32.png) [@beny18241](https://www.ruby-forum.com/u/beny18241)\
**Post date:** [May 8, 2009, 11:00am UTC](https://www.ruby-forum.com/t/grep-a-block-of-code/167397/3 "2009-05-08T11:00:09Z")

</div>

Bill K. wrote:

> From: “Maciej Pindela” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
> 
> > I’ve tried that way…
> > 
> > puts File.readlines(ARGV[0]).grep(/ \* \</tag\>/)
> 
> puts ARGF.read.scan(/.\*?\</tag\>/m)
> 
> Regards,
> 
> Bill

Thanks that’s works
