From: Alexey Bovanenko Date: 2009-10-13T04:51:01+09:00 Subject: Re: remove specific text from line Hi! I think you can use the following solution: class TestClass def test(val) val.scan(/^[^@]+@(\d{1,3}\.\d{1,3})[^*]+\*{3}\s*([^*]+)/) do puts $1+" : "+$2 end end end myInst=TestClass.new myInst.test("Time@110.075: EVENT: [LOG] *** DEBUG ACTION ***"); The result is: 110.075 : DEBUG ACTION On Mon, Oct 12, 2009 at 11:40 PM, Caleb Clausen wrote: > On 10/12/09, Collin Moore wrote: >> Hi >> thanks for all the help on my previous question, but now I am trying to >> clean up the output of some text output. >> >> currently I have: >> Time@110.075: EVENT: [LOG] *** DEBUG ACTION *** >> >> and I'd like it to have: >> 110.075:DEBUG ACTION >> >> : just for easy import into excel. >> >> Here is the current ruby file I am working with where is looked for >> lines with DEBUG and START in them. >> >> File.open('output.txt', 'w') do |f2| >> File.readlines("original.txt").each do |line| >>  if line =~ /DEBUG/ || line =~ /START/ >>     f2.puts line >>   end >> end >> end >> >> Any ideas? > > You want a regexp. Something like this should work. (Stick it in > before the puts line.) (You may need to customize depending on your > exact requirements.) > > line.sub!(/^Time@ (\d+\.\d+):.*\*{3} ([A-Z]+ [A-Z]+) \*{3}$/){ $1+':'+$2 } > >