# File operations

**URL:** <https://www.ruby-forum.com/t/file-operations/125315>\
**Category:** Ruby\
**Created:** [January 8, 2008, 5:57am UTC](https://www.ruby-forum.com/t/file-operations/125315 "2008-01-08T05:57:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![olita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/9fc348/32.png) [@olita](https://www.ruby-forum.com/u/olita)\
**Post date:** [January 8, 2008, 5:57am UTC](https://www.ruby-forum.com/t/file-operations/125315/1 "2008-01-08T05:57:20Z")

</div>

Hi,  
could you tell me how to compare 2 files (if a block of the first file  
contains the second file).  
for example.  
file 1:  
  
-----  
-----  
-----  
  
  
  
file 2:

I need to verify if the content of the 2nd file is present on the first  
file  
I hope you can help me with this

---

<div class="post-metadata">

**Author:** ![olita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/9fc348/32.png) [@olita](https://www.ruby-forum.com/u/olita)\
**Post date:** [January 8, 2008, 3:26pm UTC](https://www.ruby-forum.com/t/file-operations/125315/2 "2008-01-08T15:26:23Z")

</div>

Olita Olita wrote:

> Hi,  
> could you tell me how to compare 2 files (if a block of the first file  
> contains the second file).

You can load the two files in two strings

str1 = IO.read(“file1”)  
str2 = IO.read(“file2”)

and now search if str2 is contained in str1

… if str1.include? str2

tiziano

---

<div class="post-metadata">

**Author:** ![olita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/9fc348/32.png) [@olita](https://www.ruby-forum.com/u/olita)\
**Post date:** [January 8, 2008, 8:04pm UTC](https://www.ruby-forum.com/t/file-operations/125315/3 "2008-01-08T20:04:33Z")

</div>

Tiziano M. wrote:

> Olita Olita wrote:
> 
> > Hi,  
> > could you tell me how to compare 2 files (if a block of the first file  
> > contains the second file).
> 
> You can load the two files in two strings
> 
> str1 = IO.read(“file1”)  
> str2 = IO.read(“file2”)
> 
> and now search if str2 is contained in str1
> 
> … if str1.include? str2
> 
> tiziano

thank you 🙂 … it’s working now 😃

Olita
