# Word replacement from the file

**URL:** <https://www.ruby-forum.com/t/word-replacement-from-the-file/139627>\
**Category:** Rails\
**Created:** [June 5, 2008, 5:06pm UTC](https://www.ruby-forum.com/t/word-replacement-from-the-file/139627 "2008-06-05T17:06:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zeeshanbth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/ce73a5/32.png) [@zeeshanbth](https://www.ruby-forum.com/u/zeeshanbth)\
**Post date:** [June 5, 2008, 5:06pm UTC](https://www.ruby-forum.com/t/word-replacement-from-the-file/139627/1 "2008-06-05T17:06:07Z")

</div>

hello,

I need little help from you that i want to replace word/s from a .rb and  
.txt file. I am using the ‘gsub’ function for replacing the word from  
the string but i am not able to replace word/s from a file (.rb and  
.txt).

I will be very kind and thnkful to you if you could resolve my problem,

---

<div class="post-metadata">

**Author:** ![zeeshanbth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/ce73a5/32.png) [@zeeshanbth](https://www.ruby-forum.com/u/zeeshanbth)\
**Post date:** [June 5, 2008, 6:21pm UTC](https://www.ruby-forum.com/t/word-replacement-from-the-file/139627/2 "2008-06-05T18:21:10Z")

</div>

You can use ruby’s IO library to read the contents of a file into a  
string, or cycle through by lines, or what have you. See:  
[http://www.ruby-doc.org/core/classes/IO.html](http://www.ruby-doc.org/core/classes/IO.html)

HTH,

-Roy
