# Instead of re.sub

**URL:** <https://www.ruby-forum.com/t/instead-of-re-sub/107004>\
**Category:** Ruby\
**Created:** [June 16, 2007, 1:09pm UTC](https://www.ruby-forum.com/t/instead-of-re-sub/107004 "2007-06-16T13:09:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cihan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/94ad74/32.png) [@cihan](https://www.ruby-forum.com/u/cihan)\
**Post date:** [June 16, 2007, 1:09pm UTC](https://www.ruby-forum.com/t/instead-of-re-sub/107004/1 "2007-06-16T13:09:46Z")

</div>

hi I want to remove all \n parts of a .txt file but I can’t find the  
command.

If I use .sub the code makes the only first replacement but I need it to  
check all of the file.

In python language they use re but in ruby what should I do? please give  
me a way.

---

<div class="post-metadata">

**Author:** ![cihan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/94ad74/32.png) [@cihan](https://www.ruby-forum.com/u/cihan)\
**Post date:** [June 16, 2007, 1:24pm UTC](https://www.ruby-forum.com/t/instead-of-re-sub/107004/2 "2007-06-16T13:24:27Z")

</div>

Alle sabato 16 giugno 2007, cihan ha scritto:

> hi I want to remove all \n parts of a .txt file but I can’t find the  
> command.
> 
> If I use .sub the code makes the only first replacement but I need it to  
> check all of the file.
> 
> In python language they use re but in ruby what should I do? please give  
> me a way.

Use gsub instead of sub.

Stefano
