# Reading file after a particular line in file

**URL:** <https://www.ruby-forum.com/t/reading-file-after-a-particular-line-in-file/197136>\
**Category:** Ruby\
**Created:** [May 12, 2010, 7:22pm UTC](https://www.ruby-forum.com/t/reading-file-after-a-particular-line-in-file/197136 "2010-05-12T19:22:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vandana](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/aeb1de/32.png) [@Vandana](https://www.ruby-forum.com/u/Vandana)\
**Post date:** [May 12, 2010, 7:22pm UTC](https://www.ruby-forum.com/t/reading-file-after-a-particular-line-in-file/197136/1 "2010-05-12T19:22:06Z")

</div>

Hello All,

```
  I would like to read a file in ruby. It is a 2G file, but

```

contain useless data in the beginning portion of the file.

There is a particular pattern towards the middle of the file after  
which useful data begins. Is there a way to grep for this pattern and  
then read every line henceforth, but ignore all lines previous to line  
on which pattern found?

Thanks,  
Vandana

---

<div class="post-metadata">

**Author:** ![Vandana](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/aeb1de/32.png) [@Vandana](https://www.ruby-forum.com/u/Vandana)\
**Post date:** [May 12, 2010, 7:30pm UTC](https://www.ruby-forum.com/t/reading-file-after-a-particular-line-in-file/197136/2 "2010-05-12T19:30:58Z")

</div>

> There is a particular pattern towards the middle of the file after  
> which useful data begins. Is there a way to grep for this pattern and  
> then read every line henceforth, but ignore all lines previous to line  
> on which pattern found?

If you don’t know where it is, then you’ll probably have to parse each  
line until you reach it, then continue on.

-rp

---

<div class="post-metadata">

**Author:** ![Vandana](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/aeb1de/32.png) [@Vandana](https://www.ruby-forum.com/u/Vandana)\
**Post date:** [May 12, 2010, 7:31pm UTC](https://www.ruby-forum.com/t/reading-file-after-a-particular-line-in-file/197136/3 "2010-05-12T19:31:28Z")

</div>

On Wed, May 12, 2010 at 1:20 PM, Vandana [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hello All,
> 
> ```
> I would like to read a file in ruby. It is a 2G file, but
> 
> ```
> 
> contain useless data in the beginning portion of the file.
> 
> There is a particular pattern towards the middle of the file after  
> which useful data begins. Is there a way to grep for this pattern and  
> then read every line henceforth, but ignore all lines previous to line  
> on which pattern found?

Grep is going to have to read the file to find that pattern anyway.

–  
Rick DeNatale

Blog: [http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)  
Github: [rubyredrick (Rick DeNatale) · GitHub](http://github.com/rubyredrick)  
Twitter: @RickDeNatale  
WWR: [http://www.workingwithrails.com/person/9021-rick-denatale](http://www.workingwithrails.com/person/9021-rick-denatale)  
LinkedIn: [http://www.linkedin.com/in/rickdenatale](http://www.linkedin.com/in/rickdenatale)
