# Re: Delete line from file

**URL:** <https://www.ruby-forum.com/t/re-delete-line-from-file/81010>\
**Category:** Ruby\
**Created:** [January 3, 2007, 12:48am UTC](https://www.ruby-forum.com/t/re-delete-line-from-file/81010 "2007-01-03T00:48:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![phrogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@phrogz](https://www.ruby-forum.com/u/phrogz)\
**Post date:** [January 3, 2007, 12:48am UTC](https://www.ruby-forum.com/t/re-delete-line-from-file/81010/1 "2007-01-03T00:48:37Z")

</div>

From: removed\_email\_address@domain.invalid

> =\> [“a”, “b”, “c”, “d”, “e”, “f”]  
> irb(main):005:0\> [1,3,5].each {|e| a.slice!(e) }  
> =\> [1, 3, 5]  
> irb(main):006:0\> a  
> =\> [“a”, “c”, “d”, “f”]
> 
> You’d probably want to reverse the list of indices.

Or perhaps:  
irb(main):001:0\> a = %w{a b c d e f }  
=\> [“a”, “b”, “c”, “d”, “e”, “f”]  
irb(main):002:0\> [1,3,5].each{ |e| a[e] = nil }  
=\> [1, 3, 5]  
irb(main):003:0\> a.compact  
=\> [“a”, “c”, “e”]

Remembering, of course, that the 1st line is the 0th line number.
