From: Jeremy Bopp Date: 2011-02-02T05:47:47+09:00 Subject: Re: Search String and Delete Line Containing String On 2/1/2011 2: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 path='c:\ruby192\my_projects\IIS_Logs\ex11012607.log' search_text = %r{/memberinfo/downline/tree/canvas.asp} File.open(path) do |file| file.each_line do |line| puts(line) unless line =~ search_text end end -Jeremy