From: Robert Klemme Date: 2011-02-02T21:01:25+09:00 Subject: Re: Search String and Delete Line Containing String On Tue, Feb 1, 2011 at 9:28 PM, Bob Hatch wrote: > I am new to Ruby and am pulling my hair out on something that I know is > simple. I am searching a large text file, line by line for text that > will reside in part of the line. If it finds part of the text, I want to > delete the line. Here is what I have that is not working. Help is > appreciated! Thanks in advance! > > # process every line in a text file > file='c:\ruby192\my_projects\IIS_Logs\ex11012607.log' > text=File.readlines(file).each do |line| > search_text = "/memberinfo/downline/tree/canvas.asp" > if(line.gsub!(search_text) == search_text) then > #line.clear >  puts search_text > else >  puts "Not Found" > end > #puts line > end The simplest solution for this that I can think of is fgrep -v "/memberinfo/downline/tree/canvas.asp" 'c:\ruby192\my_projects\IIS_Logs\ex11012607.log' with proper shell tools installed. With Ruby you can do ruby -ne 'puts $_ unless %r{/memberinfo/downline/tree/canvas.asp}i =~ $_' 'c:\ruby192\my_projects\IIS_Logs\ex11012607.log' You can even do an inplace replacement of the file by inserting -i.bak in the command line. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/